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. You also need to assign the FormFieldFacade object to Facade property of the FormEditor object. 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()
        {
            var editor = new FormEditor();
            editor.BindPdf(_dataDir + "Sample-Form-01.pdf");

            var cityDecoration = new FormFieldFacade
            {
                Font = FontStyle.Courier,
                FontSize = 12,
                BorderColor = System.Drawing.Color.Black,
                BorderWidth = 2
            };

            editor.Facade = 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. You also need to assign the FormFieldFacade object to Facade property of the FormEditor object. 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 DecorateField2()
        {
            var editor = new FormEditor();
            editor.BindPdf(_dataDir + "Sample-Form-01.pdf");

            var textFieldDecoration = new FormFieldFacade
            {
                Alignment = FormFieldFacade.AlignCenter,
            };

            editor.Facade = textFieldDecoration;
            editor.DecorateField(FieldType.Text);
            editor.Save(_dataDir + "Sample-Form-01-align-text.pdf");
        }