Posted by a ceTe Software moderator
Hello Oliver,
You can add acro form fields to the PDF using DynamicPDF Generator/Merger for Java product. If you are creating PDF from scratch then below is the code sample. Also you can refer to the documentation on interactive forms
here.
Document document = new Document();
Page page = new Page(PageSize.LETTER,PageOrientation.LANDSCAPE);
document.getPages().add(page);
TextField textField = new TextField( "Text Field Name", 50, 75, 150, 30 );
textField.setBorderStyle(BorderStyle.SOLID);
textField.setDefaultValue("DynamicPDF");
textField.setMultiLine(true);
page.getElements().add(textField);
document.draw("C:/Temp/MyDocument.pdf");
If you are looking to add form field to the existing PDF then below is the code sample.
PdfDocument pdf=new PdfDocument("File path for input PDF");
MergeDocument mergeDoc=new MergeDocument(pdf);
//Access the page using index.
Page page=mergeDoc.getPages().getPage(0);
//Add the form field to the page.
TextField textField = new TextField( "txt_1", 50, 120, 150, 30 );
textField.setBorderStyle(BorderStyle.SOLID);
page.getElements().add(textField);
mergeDoc.draw("C:/Temp/MyOutput.pdf");
You can fill the form fields dynamically using DynamicPDF Merger product. You will need to access the form filed using full name or index and fill them with required text. Below is the code sample. The documentation on filling the form can be found
here.
PdfDocument pdf=new PdfDocument("File path for a input PDF");
MergeDocument mergeDoc=new MergeDocument(pdf);
mergeDoc.getForm().getFields().getFormField("Text Field Name").setValue("My Value");
mergeDoc.draw("C:/Temp/MyOutput.pdf");
Thanks,
ceTe Software Support Team