Free Support Forum - aspose.com

Bookmark/FormFields loose the replaced text values during printing output document

Hi There,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I am using an evaluation version of Aspose.Words 5.0.1.

I have a problem inserting values in Form Text Input fields. After inserting the desired values and open the generated document everything seems to be ok. But trying to print the generated document, the replaced fields are flush out, loosing so all replaced text values and become as the original status except the checkboxes.

Here I send my code example, I have simplified it to relieve just the problem.

Attached you'll see my template being used as well as the generated document for you to see.

I appreciate beforehand your help.

Kind regards,

Joshua

Document oDoc = new Document(System.IO.Path.Combine(DocPath, "VorlageEinreisegesuchDrittstaaten.doc"));

InsertTextBM(oDoc, "txtFamilienname", "Bachmann");

InsertTextBM(oDoc, "txtGeburtsname", "Bachmann");

InsertTextBM(oDoc, "txtVorname", "Peter");

InsertTextBM(oDoc, "txtGeburtsdatum", "1-Nov-2005");

InsertTextBM(oDoc, "xtStaatsAng", "USA");

InsertTextBM(oDoc, "txtStaatsAngVater", "United Kingdom");

InsertTextBM(oDoc, "txtStaatsAngMutter", "Germany");

InsertTextBM(oDoc, "Zivverheiratet", "Germany",true );

InsertTextBM(oDoc, "rbMale", "<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />Germany",true );

oDoc.Save("DemosII.doc", SaveFormat.Doc);

public void InsertTextBM(Document oDoc, string placeHolder, string replaceText)

{

FormFieldCollection documentFormFields = oDoc.Range.FormFields;

FormField docField = documentFormFields[placeHolder];

if(docField != null && docField.Type == FieldType.FieldFormTextInput)

{

docField.Result = replaceText;

}

}

public void InsertTextBM(Document oDoc,string placeHolder, string replaceText, bool chkChecked)

{

FormFieldCollection documentFormFields = oDoc.Range.FormFields;

FormField docField = documentFormFields[placeHolder];

if(docField != null)

{

if(docField.Type == FieldType.FieldFormCheckBox)

docField.Checked = chkChecked;

}

}

Hi

Thanks for your inquiry. It seems that you enabled “Update Fields” in “Print Options” (Tools / Options / Print / Update Fields checkbox). Try disabling this option.

Hope this helps.

Best regards.

Hi Alexey,

You alright, this option is activated, the problem is that I can't tell all users to change this option for the whole company, since this options is activated in the MSWord package of my company. Is there another way to challenge this?

Is there any workaround we can do? - but it's not a big deal if not possible

I appreciate very much your support.

Regards, Josue

Hi

I think you can try using the following code as workaround.

public void InsertTextBM(Document oDoc, string placeHolder, string replaceText)

{

FormFieldCollection documentFormFields = oDoc.Range.FormFields;

FormField docField = documentFormFields[placeHolder];

if (docField != null && docField.Type == FieldType.FieldFormTextInput)

{

DocumentBuilder builder = new DocumentBuilder(oDoc);

builder.MoveToBookmark(placeHolder);

builder.Write(replaceText);

docField.Result = string.Empty;

}

}

I hope this could help you.

Best regards.

It works! Thanks a lot.

Regards,

Joshua