Add editable TextField to PDF with custom size

Hi,

I’m trying to add an editable text field into PDF from a Word template in .NET.

When I replace a tag in the Word with a TextInput using the following method, it works fine:

aDoc.Range.Replace(new Regex("@Test"), new ReplaceWithInputText(), false);

private class ReplaceWithInputText : IReplacingCallback
{
    ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)
    {
        DocumentBuilder builder = new DocumentBuilder((Word.Document)e.MatchNode.Document);

        builder.MoveTo(e.MatchNode);                 

        builder.InsertTextInput(" ", TextFormFieldType.Regular, "", "", 200);

        return ReplaceAction.Replace;
    }
}

The problem is I can’t set a custom size to this InputText (width and height).

Is there any other way to replace a tag in the Word template with an editable text field and set width and height, like a HTML TextArea tag?

Maybe replace it in the PDF after is converted from the Word template?

Thank’s in advance.

@JCDLM

Please use the PdfSaveOptions.PreserveFormFields property to specify whether to preserve Microsoft Word form fields as form fields in PDF or convert them to text. You can set the value of this property to true to get the desired output.

Please note that Aspose.Words mimics the behavior of MS Word. It does not provide a way to set the width of text form field. However, you can increase the width of text form field by setting its text with empty spaces.

Thank’s for the reply,

Already tried about the empty spaces but it’s not the way I think it should be done.

I’ll keep looking for a different way to implement that functionality.

Regards.

@JCDLM

You can achieve your requirement in two steps. First you need to convert document to PDF using Aspose.Words. After that you need to use Aspose.PDF to set the field’s with in PDF file using TextBoxField.Width property. Hope this helps you.

1 Like