We are currently porting our code base from iText 2.1.7 to iText 5.5.0 (yeah I know.. we had a little longer ;-).
Well.. "now" that copyAcroForm has gone the way of the Dodo, I'm struggling to find an alternative to this code:
File outputFile = new File...
Document document = new Document();
FileOutputStream fos = new FileOutputStream(outputFile);
PdfCopy subjobWriter = new PdfCopy(document, fos);
document.open();
PdfReader reader = new PdfReader(generationReader);
for (int i=1; i<=reader.getNumberOfPages(); i++) {
PdfImportedPage page = subjobWriter.getImportedPage(reader, i);
subjobWriter.addPage(page);
}
PRAcroForm form = reader.getAcroForm();
if (form != null)
subjobWriter.copyAcroForm(reader);
subjobWriter.freeReader(reader);
reader.close();
subjobWriter.close();
document.close();
fos.close();
but haven't really found anything. I read in the changelog of 4.34 or so that I apparently should use PdfCopy.addDocument(). I tried that and commented out the other code, such as this:
...
PdfReader reader = new PdfReader(generationReader);
reader.consolidateNamedDestinations();
subjobWriter.addDocument(reader);
subjobWriter.freeReader(reader);
subjobWriter.setOutlines(SimpleBookmark.getBookmark(reader));
...
but that didn't help either.
The problem is, that everything from the original PDF is copied EXCEPT the form (and its fields and content), or rather, it looks like the whole form has been flattened instead.
Since all the samples I could find either used copyAcroForm() which doesn't exist anymore or the PdfCopyFields class which is deprecated and all the samples at itextpdf.com and the "iText in Action, 2nd edition" use copyAcroForm() as well, I'm at loss as to how to solve this. Any idea anyone?
Rog
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…