Free Support Forum - aspose.com

Complex Form Fields

I am currently evaluating ASPOSE.Words to replace an editorial application which uses automation to replace fields in set of reports. This works fine with simple form fields, but some fields need to support rich text formatting, including tables. The process I am trying to use is as follows:

1. Retrieve document template from database and load into Aspose document.

2. Retrieve current values including rtf from the database.

3. Replace form fields with current values and display to user.

In the third step, I am attempting to create a new Document based on the rtf, convert it to Word and then put it in the form field. The question is how to get the document in the form field. I only seem to be able to put Run elements in the form field, but then I lose all the formatting

Hi

Thank you for your interest in Aspose products. Unfortunately you can’t insert document into the form field. This is known issue (#950). But you can insert a document after form field using the following code.

Document doc = new Document(@"332_101376_timcoombe\in.doc");

Document doc1 = new Document(@"332_101376_timcoombe\in1.rtf");

InsertDocument(doc.Range.Bookmarks["test"].BookmarkStart.ParentNode, doc1);

doc.Save(@"332_101376_timcoombe\out.doc");

InserDocument method you can find here.

http://www.aspose.com/Products/Aspose.Words/Api/InsertOneDocumentintoAnotheratAnyLocation.html

I hope that it will help you.

Best regards.

Hi,

Thanks for the reply. Is there anywhere I can read up on issue #950? Can I insert anything other than a Run into a form field?

Regards

Tim

Hi again

Issue #950Make it possible to insert multiple paragraphs into a text input form field.

Ii seems that I found a workaround for you. See the following code. This code inserts a document into the text form field. The document (in.doc) contains one formfield.

//Open the destination document

Document doc = new Document(@"332_101376_timcoombe\in.doc");

//Open the source document

Document doc1 = new Document(@"332_101376_timcoombe\in1.rtf");

//get collection of FieldSeperators

NodeCollection collect = doc.GetChildNodes(NodeType.FieldSeparator, true);

//Split paragraph

Paragraph par1 = (collect[0] as FieldSeparator).ParentParagraph;

Paragraph par2 = (Paragraph)par1.Clone(true);

par1.ParentSection.Body.InsertAfter(par2, par1);

//remove all nodes after FieldSeparator in Par1

for (int i = par1.ChildNodes.Count - 1; i >= 0; i--)

{

if (par1.LastChild.NodeType != NodeType.FieldSeparator)

{

par1.LastChild.Remove();

}

else

{

break;

}

}

//Remove all nodes before FieldSeparator in Par2

for (int i = 0; i < par2.ChildNodes.Count; i++)

{

if (par2.ChildNodes[0].NodeType != NodeType.FieldSeparator)

{

par2.FirstChild.Remove();

}

else

{

par2.FirstChild.Remove();

break;

}

}

//insert document between par and par2 (into FormField)

InsertDocument(par1, doc1);

//save document

doc.Save(@"332_101376_timcoombe\out.doc");

I hope that this code will help you.

Let me know if you would like to know some thing else.

Best regards.

Hi Alexey,

Many thanks! I have been trying to work that one out for some hours and your solution worked brilliantly.

Regards

Tim.