Decorate Form Field in PDF
Decorate a Particular Form Field in an Existing PDF File
decorateField method present in FormEditor class allows you to decorate a particular form field in a PDF file. If you want to decorate a particular field then you need to pass the field name to this method. However, before calling this method, you need to create objects of FormEditor and FormFieldFacade classes. After that, you can set any attributes provided by FormFieldFacade object. Once you have set the attributes, you can call the decorateField method and finally save the updated PDF using Save method of FormEditor class. The following code snippet shows you how to decorate a particular form field.
public static void DecorateField() {
FormEditor editor = new FormEditor();
editor.bindPdf(_dataDir + "Sample-Form-01.pdf");
FormFieldFacade cityDecoration = new FormFieldFacade();
cityDecoration.setFont(FontStyle.Courier);
cityDecoration.setFontSize(12);
cityDecoration.setBorderColor(Color.BLACK);
cityDecoration.setBorderWidth(2);
editor.setFacade(cityDecoration);
editor.decorateField("City");
editor.save(_dataDir + "Sample-Form-02.pdf");
}
Decorate All Fields of a Particular Type in an Existing PDF File
decorateField method allows you to decorate all the form fields of a particular type in a PDF file at once. If you want to decorate all fields of a particular type then you need to pass the field type to this method. However, before calling this method, you need to create objects of FormEditor and FormFieldFacade classes. After that, you can set any attributes provided by FormFieldFacade object. Once you have set the attributes, you can call the decorateField method and finally save the updated PDF using Save method of FormEditor class. The following code snippet shows you how to decorate all the fields of a particular type.
public static void DecorateFields() {
FormEditor editor = new FormEditor();
editor.bindPdf(_dataDir + "Sample-Form-01.pdf");
FormFieldFacade textFieldDecoration = new FormFieldFacade();
textFieldDecoration.setAlignment(FormFieldFacade.ALIGN_CENTER);
editor.setFacade(textFieldDecoration);
editor.decorateField(FieldType.Text);
editor.save(_dataDir + "Sample-Form-01-align-text.pdf");
}