[
https://issues.apache.org/jira/browse/PDFBOX-1546?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13610006#comment-13610006
]
Ken White commented on PDFBOX-1546:
-----------------------------------
Here is the code to remove the first 5 pages.
public void removePages() throws AppException {
if (pageRangeOption == 1) {
((AppPM) getFacesPresentationManager()).setPdfDoc(null);
deletePdfDoc();
} else {
if (firstPage == null || lastPage == null) {
setMessage(new AppException("You must specify
the first and last pages in the range!"));
} else {
PDDocument pdfDoc = ((AppPM)
getFacesPresentationManager()).getPdfDoc();
if (pdfDoc != null) {
int numPages =
pdfDoc.getNumberOfPages();
if (firstPage.intValue() < 1 ||
lastPage.intValue() > numPages || firstPage.intValue() > lastPage.intValue()) {
setMessage(new
AppException("The page range specified is invalid!"));
} else {
boolean isPdfDocEmpty = false;
// Delete the pages starting at
the last page in the range to avoid upsetting the page numbering
for (int i =
lastPage.intValue() - 1; i >= firstPage.intValue() - 1; i--) {
if
(pdfDoc.getNumberOfPages() > 1) {
pdfDoc.removePage(i);
} else {
// When there
is only 1 page left just mark the document as empty
isPdfDocEmpty =
true;
}
}
if (isPdfDocEmpty) {
((AppPM)
getFacesPresentationManager()).setPdfDoc(null);
deletePdfDoc();
} else {
// Update the pdfDoc in
the file system
try {
pdfDoc.save(pdfDocFileName);
} catch
(COSVisitorException error) {
throw new
AppException(error.getMessage());
} catch (IOException
error) {
throw new
AppException(error.getMessage());
}
}
}
} else {
setMessage(new AppException("The pdf
document is empty!"));
}
}
}
}
> The document's page tree contains an invalid node
> -------------------------------------------------
>
> Key: PDFBOX-1546
> URL: https://issues.apache.org/jira/browse/PDFBOX-1546
> Project: PDFBox
> Issue Type: Bug
> Components: PDModel
> Affects Versions: 1.7.1
> Environment: Windows 7 adobe reader 10.1.0
> Reporter: Ken White
> Labels: newbie
> Attachments: test.modified_by_pdfbox.pdf, test.pdf
>
>
> After removing some pages and saving the PDDocument opening the document with
> adobe reader gives the following error.
> The document's page tree contains an invalid node
> The original document does not.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira