Posted by a ceTe Software moderator
Hello,
Removing the document pages using the Iterator will most likely throw the “Invalid page number” error, because the documents that has form fields has Xref table which stores the relationships between the objects and using the iterator will only remove the page but not the entries of the removed objects in other pages. In order to avoid this error while removing pages from the document use the overloaded append method to copy only the necessary pages to a different document.
PdfDocument pdfDocument = new PdfDocument("F:/temporary/CustomerPDF/test.pdf");
MergeOptions options=new MergeOptions();
options.setFormFields(true);
MergeDocument tempDoc = new MergeDocument();
tempDoc.append(pdfDocument, 2, (pdfDocument.getPages().getSize()-1),options);
if (tempDoc != null)
{
String name = "F:/temporary/CustomerPDF/final.pdf";
tempDoc.draw(name);
}
Thanks,
ceTe Software Support Team.