Hello,
Suppose I have a document that holds only a PDF form created with Adobe Acrobat. I need to load the PDF document, populate the placeholders with values and import the area into another document. This works fine, however I need in some cases the form fields to still be editable by the user and this is not possible if imported using ImportedPageArea? The code snippet is included below.
How should the code below be changed for the PDF form fields to be populated but still editable?
Thanks in advance,
Best regards,
Giovanni
// load existing PDF document containing form
PdfDocument pdfDocument = new PdfDocument(fileName);
MergeDocument mergeDocument = new MergeDocument(pdfDocument);
// populate placeholders
Map<String, String> replacements = new HashMap<String, String>();
for (Map.Entry<String, String> entry : replacements.entrySet()) {
PdfFormField field = pdfDocument.getForm().getFields().getPdfFormField(entry.getKey());
field.createLabel(mergeDocument.getPages().getPage(field.getOriginalPageNumber() - 1), entry.getValue(), Font.getTimesRoman(), 12);
}
// output the populated template to a pdfDocument
byte[] data = mergeDocument.draw();
pdfDocument = new PdfDocument(data);
// create an imported area from the in-memory pdfDocument
int pageOne = 1;
int xOffset = 50;
int yOffset = 550;
ImportedPageArea importedArea = new ImportedPageArea(pdfDocument.getPage(pageOne), xOffset, yOffset);
importedArea.getContents().setClipLeft(0);
importedArea.getContents().setClipTop(0);
importedArea.getContents().setClipRight(0);
importedArea.getContents().setClipBottom(0);