Search in sources :

Example 1 with PDPageFitDestination

use of com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageFitDestination in project PdfBox-Android by TomRoush.

the class PDFMergerUtilityTest method testPDFMergerOpenAction.

/**
 * PDFBOX-3972: Test that OpenAction page destination isn't lost after merge.
 *
 * @throws IOException
 */
@Test
public void testPDFMergerOpenAction() throws IOException {
    PDDocument doc1 = new PDDocument();
    doc1.addPage(new PDPage());
    doc1.addPage(new PDPage());
    doc1.addPage(new PDPage());
    doc1.save(new File(TARGETTESTDIR, "MergerOpenActionTest1.pdf"));
    doc1.close();
    PDDocument doc2 = new PDDocument();
    doc2.addPage(new PDPage());
    doc2.addPage(new PDPage());
    doc2.addPage(new PDPage());
    PDPageDestination dest = new PDPageFitDestination();
    dest.setPage(doc2.getPage(1));
    doc2.getDocumentCatalog().setOpenAction(dest);
    doc2.save(new File(TARGETTESTDIR, "MergerOpenActionTest2.pdf"));
    doc2.close();
    PDFMergerUtility pdfMergerUtility = new PDFMergerUtility();
    pdfMergerUtility.addSource(new File(TARGETTESTDIR, "MergerOpenActionTest1.pdf"));
    pdfMergerUtility.addSource(new File(TARGETTESTDIR, "MergerOpenActionTest2.pdf"));
    pdfMergerUtility.setDestinationFileName(TARGETTESTDIR + "MergerOpenActionTestResult.pdf");
    pdfMergerUtility.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
    PDDocument mergedDoc = PDDocument.load(new File(TARGETTESTDIR, "MergerOpenActionTestResult.pdf"));
    PDDocumentCatalog documentCatalog = mergedDoc.getDocumentCatalog();
    dest = (PDPageDestination) documentCatalog.getOpenAction();
    assertEquals(4, documentCatalog.getPages().indexOf(dest.getPage()));
    mergedDoc.close();
}
Also used : PDPage(com.tom_roush.pdfbox.pdmodel.PDPage) PDDocument(com.tom_roush.pdfbox.pdmodel.PDDocument) PDPageDestination(com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination) PDPageFitDestination(com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageFitDestination) File(java.io.File) PDDocumentCatalog(com.tom_roush.pdfbox.pdmodel.PDDocumentCatalog) Test(org.junit.Test)

Aggregations

PDDocument (com.tom_roush.pdfbox.pdmodel.PDDocument)1 PDDocumentCatalog (com.tom_roush.pdfbox.pdmodel.PDDocumentCatalog)1 PDPage (com.tom_roush.pdfbox.pdmodel.PDPage)1 PDPageDestination (com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination)1 PDPageFitDestination (com.tom_roush.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageFitDestination)1 File (java.io.File)1 Test (org.junit.Test)1