[
https://issues.apache.org/jira/browse/PDFBOX-2400?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14954798#comment-14954798
]
adam Retter edited comment on PDFBOX-2400 at 10/13/15 11:31 AM:
----------------------------------------------------------------
So as a follow up, [~msahyoun] very kindly suggested this solution for
appending a page on the mailing list:
PDDocument document = PDDocument.load(…)
PDPage pageToInsert = new PDPage();
PDPageTree pageTree = document.getPages();
COSDictionary pagesDictionary = (COSDictionary)
document.getDocumentCatalog().getCOSObject().getDictionaryObject(COSName.PAGES);
COSArray kids = (COSArray)
pagesDictionary.getDictionaryObject(COSName.KIDS);
kids.add(0,pageToInsert.getCOSObject());
pageToInsert.getCOSObject().setItem(COSName.PARENT, pagesDictionary);
pagesDictionary.setInt(COSName.COUNT,
pagesDictionary.getInt(COSName.COUNT) + 1);
document.save(...);
document.close();
It appears to work perfectly for my use-case. Thanks.
was (Author: adamretter):
So as a follow up, [~msahyoun] verky kindly suggested this solution for
appending a page on the mailing list:
PDDocument document = PDDocument.load(…)
PDPage pageToInsert = new PDPage();
PDPageTree pageTree = document.getPages();
COSDictionary pagesDictionary = (COSDictionary)
document.getDocumentCatalog().getCOSObject().getDictionaryObject(COSName.PAGES);
COSArray kids = (COSArray)
pagesDictionary.getDictionaryObject(COSName.KIDS);
kids.add(0,pageToInsert.getCOSObject());
pageToInsert.getCOSObject().setItem(COSName.PARENT, pagesDictionary);
pagesDictionary.setInt(COSName.COUNT,
pagesDictionary.getInt(COSName.COUNT) + 1);
document.save(...);
document.close();
> Add insertPage() method
> -----------------------
>
> Key: PDFBOX-2400
> URL: https://issues.apache.org/jira/browse/PDFBOX-2400
> Project: PDFBox
> Issue Type: New Feature
> Components: PDModel
> Affects Versions: 1.8.7, 2.0.0
> Reporter: Patrick Tucker
> Priority: Minor
> Fix For: 2.1.0
>
>
> It would be nice if PDDocument had an insertPage function similar to addPage,
> but takes a number to indicate where to add the new page in the current set
> of pages.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]