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

Sascha Becher commented on PDFBOX-3815:
---------------------------------------

The problem occured after merging the first page with the last page.
Background: Eclipse BIRT reporting (which created the PDF) has page break 
issues when changing the master page on pages
with content that has dynamic length.
My workaround was to skip the header and footer on page 1, add a last page with 
that header and footer and merge
the first page onto the last, remove page 0 (this didn't work) and move the 
last page to the first page. Done with:

                PDPageTree pages = originalDoc.getDocumentCatalog().getPages();
                PDPage firstPage = pages.get(0);
                try (PDDocument overlayDocument = new PDDocument()) {
                        overlayDocument.addPage(firstPage);

                        Overlay overlay = new Overlay();
                        overlay.setOverlayPosition(Overlay.Position.FOREGROUND);
                        overlay.setInputPDF(originalDoc);
                        overlay.setLastPageOverlayPDF(overlayDocument);

                        Map<Integer, String> ovmap = new HashMap<>();
                        overlay.overlay(ovmap); // required
                        overlayDocument.close();
                }
                originalDoc.save(newFile);
                originalDoc.close();

I then had to replace text (page counter are also a malignant feature of BIRT 
when total page count is required to be smaller than the actual) which isn't 
possible in overlayed text. This is why I merged the text from page 1 onto the 
last page with header/footer, because the placeholder for page number is in the 
footer, not in the text. I'm aware that replacing text in a PDF isn't a good 
idea.
Maybe my initial problem was that I didn't understand how to properly merge two 
PDF pages other than with new Overlay().

> Removing the first page doesn't work
> ------------------------------------
>
>                 Key: PDFBOX-3815
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-3815
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 2.0.6
>         Environment: Windows 10, Java 8; PDF 1.5
>            Reporter: Sascha Becher
>
> Does nothing to page 1:
> try (PDDocument doc = PDDocument.load(file)) {
>       doc.removePage(0);
>       doc.save(file);
>       doc.close();
> }
> This would remove page 2:
> doc.removePage(1);
> seems not to be new: 
> https://stackoverflow.com/questions/37865415/pdfbox-does-not-remove-first-page
> If there are any restrictions to removing pages, the javadoc should note this.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

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

Reply via email to