Add textarea to word document

Hello,
We recently had the source code given to us by a vendor for a website they created for us. The application uses Aspose.Words (13.7.0.0) to take an online form and convert it to a word document. The issue we are having is when it comes to a multiline textbox (textarea). We can’t seem to add one to the word document.
I did see a post that said adding a textarea to a word document wasn’t possible but it was a few years old and maybe something has changed since then.
Does anyone know of a way to accomplish this? Any help is appreciated.
Thanks

Hi John,

Thanks for your inquiry. Please use the following code example to achieve your requirements. Hope this helps you.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape textBox = new Shape(builder.Document, ShapeType.TextBox);
textBox.Height = 100;
textBox.Width = 200;
textBox.AppendChild(new Paragraph(doc));
textBox.TextBox.FitShapeToText = true;
Paragraph para = textBox.FirstParagraph;
// Add some text to the paragraph.
Run run = new Run(doc);
run.Text = @"Aspose.Words for .NET is a class library that enables your applications to perform a great range of document processing tasks. Aspose.Words supports DOC, DOCX, RTF, HTML, OpenDocument, PDF, XPS, EPUB and other formats. With Aspose.Words you can generate, modify, convert, render and print documents without utilizing Microsoft Word®.";
para.AppendChild(run);
doc.FirstSection.Body.FirstParagraph.AppendChild(textBox);
doc.Save(MyDir + "Out.docx");

If you still face problem, please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.

Hi Tahir,

Thank you for your quick reply and I apologize for taking so long to get back to you.

The code provided did in fact create the text area as written however it prompted a couple of other questions but I think I should probably tell you how it works now too.

All of these forms have both an “online” form and “offline” form. The “online” form is just a regular asp.net web form. The “offline” form is what we use Aspose for. The source that is already generated for the web form is then used to create a new Aspose.Words document. The various fields on the form are converted to Word form fields so the initial problem was there is no form field for a text area. The reason for using form fields was nice because it allowed the document to be protected only allowing the form fields to be edited.

The code you provided created the text area but was unfortunately made read only when the document was protected. Is there a way make it editable while still protecting the other parts of the form? Would we be better off creating the document by adding the fields one at a time as opposed to building it with the html source?

I have attached a document showing the vendor’s solution to this problem and the box that was created with the code you suggested.

Thank you.

Hi John,

Thanks for sharing the detail. In your case, I suggest you please insert the text form field. If the contents of text form field grows, its size also grow. Please use the following code example and check the attached output document. If this does not help you, please create your expected output document here for our reference. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertTextInput("TextInput", TextFormFieldType.Regular, "", @"Aspose.Words for .NET is a class library that enables your applications to perform a great range of document processing tasks. Aspose.Words supports DOC, DOCX, RTF, HTML, OpenDocument, PDF, XPS, EPUB and other formats. With Aspose.Words you can generate, modify, convert, render and print documents without utilizing Microsoft Word®.", 0);
// Section protection only works when document protection is turned and only editing in form fields is allowed.
doc.Protect(ProtectionType.AllowOnlyFormFields);
doc.Save(MyDir + "Out.docx");