set size of Formfield

I would like to set the size of a formfield in the editor for I have used your  https://support.syncfusion.com/kb/article/11438/how-to-add-signature-field-in-the-pdf-converted-from-word for adding a signature to the pdf using a formfield, but the sizing is off. would like to set width and height


1 Reply

DS Dhanush Sekar Syncfusion Team January 23, 2025 02:21 PM UTC

Hi White Wolfza,


You can specify the size for a checkbox field. However, it is not feasible to specify the height for a text form field, as it will automatically adjust based on the text provided. You can specify the font size, and the text form field will expand to fit the content.
Kindly refer to the code snippet below.

WordDocument document = new WordDocument(@"../../../Input.docx");

List<Entity> checkBoxes = document.FindAllItemsByProperty(EntityType.CheckBox, null, null);

foreach (Entity entity in checkBoxes)

{

    WCheckBox checkBox = (WCheckBox)entity;

    checkBox.SizeType = CheckBoxSizeType.Exactly;

    checkBox.CheckBoxSize = 20;

}

List<Entity> textFormFields = document.FindAllItemsByProperty(EntityType.TextFormField, null, null);

foreach (Entity entity in textFormFields)

{

    WTextFormField textFormField = (WTextFormField)entity;

    textFormField.Text = "Adventure work cycles";

    Entity currentEntity = textFormField;

    //Iterates to sibling items until Field End

    while (currentEntity.NextSibling != null)

    {

        if (currentEntity is WTextRange)

            //Sets character format for text ranges

            (currentEntity as WTextRange).CharacterFormat.FontSize = 30;

        else if ((currentEntity is WFieldMark) && (currentEntity as WFieldMark).Type == FieldMarkType.FieldEnd)

            break;

        //Gets next sibling item.

        currentEntity = (Entity)currentEntity.NextSibling;

    }

}

document.Save(@"../../../Result.docx");


In this case, you can retrieve specific form fields in the document using the FindAllItemsByProperty() method.

For more detailed information about form fields,
Refer UG: Working with Form Fields | DocIO | Syncfusion®


Regards,

Dhanush S


Loader.
Up arrow icon