We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Preserve Style after inserting text in content control

I’d like to insert content control and choose a formatting style for the content.
After inserting the value of content, I’d like to have my formatting style preserved.
Right now I do something like:
for (StructuredDocumentTag sdt : (Iterable) doc
.getChildNodes(NodeType.STRUCTURED_DOCUMENT_TAG, true)) {
if (sdt.getSdtType() == SdtType.PLAIN_TEXT
|| sdt.getSdtType() == SdtType.RICH_TEXT) {

			String value = nomeVariabili.get(sdt.getTag());
			if (value != null) {
				if (sdt.getLevel() == MarkupLevel.BLOCK) {
					Paragraph para = (Paragraph) sdt
							.appendChild(new Paragraph(doc));
					Run run = new Run(doc, value);
				} else if (sdt.getLevel() == MarkupLevel.INLINE) {

					sdt.appendChild(new Run(doc, value));



I also tried to clone the first child of the sdt, before removing all children and paste it with my updated content, without the expected result.
Thank you for your help.

Hi Danilo,

Thanks for your inquiry. You are removing the all children nodes of content control and insert new contents. In this case, default formatting will be applied to content control.

I suggest you please remove all children node of first paragraph of content control. Use DocumentBuilder.MoveTo method to move the cursor to the first paragraph of content control and write the contents using DocumentBuilder.Writeln method. Hope this helps you.

If you still face problem, please share your input and expected output document here for our testing purposes. I will investigate the issue and provide you more information on this issue.