[ 
https://issues.apache.org/jira/browse/PDFBOX-6283?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Tilman Hausherr resolved PDFBOX-6283.
-------------------------------------
    Fix Version/s: 2.0.38
                   3.0.9 PDFBox
                   4.0.0
         Assignee: Tilman Hausherr
       Resolution: Fixed

> Splitting a pdf does not keep the Catalog names dict
> ----------------------------------------------------
>
>                 Key: PDFBOX-6283
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-6283
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 2.0.37, 3.0.8 PDFBox
>            Reporter: Simon Steiner
>            Assignee: Tilman Hausherr
>            Priority: Major
>              Labels: split
>             Fix For: 2.0.38, 3.0.9 PDFBox, 4.0.0
>
>
> When I split a pdf, i would expect the Catalog to have a names entry with the 
> names that refer to the current page of the split
> {code:java}
> /**
>      * Verifies that named destinations (/Names /Dests) pointing to a page 
> are copied to the split
>      * document that contains that page, remapped to the imported page, and 
> that destinations
>      * pointing to other pages are not carried over.
>      */
>     @Test
>     public void testSplitCopiesNamedDestinations() throws Exception {
>         PDDocument document = new PDDocument();
>         PDPage page0 = new PDPage();
>         PDPage page1 = new PDPage();
>         PDPage page2 = new PDPage();
>         document.addPage(page0);
>         document.addPage(page1);
>         document.addPage(page2);
>         PDPageFitDestination dest0 = new PDPageFitDestination();
>         dest0.setPage(page0);
>         PDPageFitDestination dest1 = new PDPageFitDestination();
>         dest1.setPage(page1);
>         PDPageFitDestination dest2 = new PDPageFitDestination();
>         dest2.setPage(page2);
>         Map<String, COSObjectable> destNames = new LinkedHashMap<String, 
> COSObjectable>();
>         destNames.put("dest0", dest0);
>         destNames.put("dest1", dest1);
>         destNames.put("dest2", dest2);
>         PDDocumentNameDictionary names = new 
> PDDocumentNameDictionary(document.getDocumentCatalog());
>         PDDestinationNameTreeNode dests = new PDDestinationNameTreeNode();
>         dests.setNames(destNames);
>         names.setDests(dests);
>         document.getDocumentCatalog().setNames(names);
>         List<PDDocument> split = new Splitter().split(document);
>         Assert.assertEquals(3, split.size());
>         for (int i = 0; i < split.size(); i++) {
>             PDDocument splitDocument = split.get(i);
>             PDDocumentNameDictionary splitNames = 
> splitDocument.getDocumentCatalog().getNames();
>             Assert.assertNotNull("split document " + i + " should have a name 
> dictionary", splitNames);
>             Assert.assertNotNull("split document " + i + " should have a 
> dests node", splitNames.getDests());
>             Map<String, COSObjectable> copiedNames = 
> splitNames.getDests().getNames();
>             Assert.assertNotNull(copiedNames);
>             // only the destination pointing to this page should be present
>             Assert.assertEquals(1, copiedNames.size());
>             String expectedName = "dest" + i;
>             COSObjectable copied = copiedNames.get(expectedName);
>             Assert.assertTrue(copied instanceof PDPageFitDestination);
>             // the destination must point to the imported page of the split 
> document
>             PDPage importedPage = ((PDPageFitDestination) copied).getPage();
>             Assert.assertSame(splitDocument.getPage(0).getCOSObject(), 
> importedPage.getCOSObject());
>         }
>     }
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to