Dear Aspose.Tech, I need your help:
I have a project where i need to use an existing Fillable PDF Form as input.
I need to write regular Text on this document, but it not working, text never show on final PDF…
Also i need to populate some fields in this form but when i selected an item from the combobox but it does not work, meaning it does not select anything and the final PDF output shows no selection…
Please see attached PDF. i use for input form.
My Environment: Win10, Java 8, Aspose.PDF 19.5, Eclipse 2019-03
my Code bellow:
import com.aspose.pdf.Color;
import com.aspose.pdf.ComboBoxField;
import com.aspose.pdf.Document;
import com.aspose.pdf.FontRepository;
import com.aspose.pdf.Page;
import com.aspose.pdf.Position;
import com.aspose.pdf.TextBuilder;
import com.aspose.pdf.TextFragment;
public class WriteTextOnPDF {
public static void main(String[] args) {
com.aspose.pdf.License license = new com.aspose.pdf.License();
// Call setLicense method to set license
try {
license.setLicense("Aspose.Total.Java.lic");
} catch (Exception e) {
e.printStackTrace();
}
// Open a document
String docIn = "C:\\TEMP\\PDF\\FORMMA4.pdf";
Document pdfDocument = new Document(docIn.trim());
Page pdfPage = pdfDocument.getPages().get_Item(1);
// create text fragment
TextFragment textFragment = new TextFragment("THIS IS NEW TEXT ADDED BY CODE");
textFragment.setPosition(new Position(100, 300));
// set text properties
textFragment.getTextState().setFont(FontRepository.findFont("Verdana"));
textFragment.getTextState().setFontSize(14);
textFragment.getTextState().setForegroundColor(Color.getBlue());
textFragment.getTextState().setBackgroundColor(Color.getGray());
// create TextBuilder object
TextBuilder textBuilder = new TextBuilder(pdfPage);
// append the text fragment to the PDF page
//THE TEXT DOES NOT WORK , DOES NOT SHOWS in FINAL PDF ???
textBuilder.appendText(textFragment);
//THIS CODE DOES NOT WORK ???
//I need to make a selection from ComboBox field here
ComboBoxField comboBoxField = (com.aspose.pdf.ComboBoxField) pdfDocument.getForm().get("form1[0].#subform[0].DropDownList1[0]");
comboBoxField.setSelected(3);
// Save the updated document
String docOut = "C:\\TEMP\\PDF\\OUT_FORMMA4.pdf";
pdfDocument.save(docOut);
System.out.println("<< END OF JOB... >>");
}
}FormMA4.pdf (154.8 KB)