[ 
https://issues.apache.org/jira/browse/PDFBOX-6202?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18081220#comment-18081220
 ] 

Andreas Lehmkühler commented on PDFBOX-6202:
--------------------------------------------

We've implemented "importPage" for a good reason. It handles overlapping object 
numbers if an existing page from one pdf is added to another one. If you don't 
use it you have to deal with such cases yourself. 

However, the fix from PDFBOX-6203 solves the issue with the two given pdfs as 
well. But be aware that there is no guarantee that it works in every case. You 
have to keep in mind that you have to deal with overlapping/double object keys 
if two pdfs are merged.



> Possible regression when combining multiple PDFs
> ------------------------------------------------
>
>                 Key: PDFBOX-6202
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-6202
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 3.0.7 PDFBox
>            Reporter: Alexander Pinske
>            Priority: Major
>         Attachments: X1.pdf, X2.pdf, X_actual.pdf, X_expected.pdf
>
>
> Worked in 3.0.6, might be a regression caused by PDFBOX-6036.
> {code:java}
>     @Test
>     void testPDFBoxX() throws IOException
>     {
>         try (PDDocument d1 = Loader.loadPDF(new 
> RandomAccessReadBuffer(getClass().getResourceAsStream("/input/X1.pdf")));
>              PDDocument d2 = Loader.loadPDF(new 
> RandomAccessReadBuffer(getClass().getResourceAsStream("/input/X2.pdf")));
>              PDDocument d = new PDDocument()) {
>             List<PDPage> pages = new ArrayList<>();
>             d1.getPages().forEach(pages::add);
>             d2.getPages().forEach(pages::add);
>             for (PDPage page : pages) {
>                 d.addPage(page);
>             }
>             d.save(new FileOutputStream("target/X.pdf"));
>         }
>     }
> {code}
> It starts working again, when I add this line before the call to addPage:
> {code:java}
> page.getCOSObject().resetImportedObjectKeys();
> {code}
> I do know about importPage, but we are not using that to avoid an extra copy, 
> as the source pdfs are discarded after.



--
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