Content Control visible in WPS but not visible in MS word

Hi team,

I am creating content contol with below code.
SDT is getting created successfully and visible in WPS but same is not visible in MS word.

Code Snippet:

public void createSDT(Document document, CustomNode customNode){
        var sectionSDT = this.sdtCreationService.createNewStructureDocumentTag(document);
        this.sdtCreationService.makeParaChildOfSDTSectionParsing(customNode, sectionSDT);
    }

public class StructureDocumentTagCreationService {

    @Autowired
    private NodeUtil nodeUtil;

    private static final String TAG_CREATION_ERROR_MESSAGE = "Not able to create structureDocumentTag in document due to : %s";
    private static final String SDT_INSERTION_ERROR_MESSAGE = "Not able to insert SDT before para due to : %s";

    public StructuredDocumentTag createNewStructureDocumentTag(Document document) {
        return this.createNewStructureDocumentTag(document, SdtType.RICH_TEXT);
    }

    public StructuredDocumentTag createNewStructureDocumentTag(Document document, Integer sdtType) {
        StructuredDocumentTag structuredDocumentTag;
        try {
            structuredDocumentTag = new StructuredDocumentTag(document, sdtType, MarkupLevel.BLOCK);
            structuredDocumentTag.removeAllChildren();
            var uuId = UUID.randomUUID().toString();
            structuredDocumentTag.setTitle(uuId);
            structuredDocumentTag.setTag(uuId);
            structuredDocumentTag.isShowingPlaceholderText(false);
        } catch (Exception ex) {
            throw new CustomException(TAG_CREATION_ERROR_MESSAGE.formatted(ex.getMessage()), null);
        }
        return structuredDocumentTag;
    }

    public void makeParaChildOfStructuredDocumentTag(Paragraph para, StructuredDocumentTag structuredDocumentTag, boolean isContentControl, boolean docTaggingEnabled) {
        var parentNode = para.getParentNode();
        if (!isContentControl && Objects.nonNull(parentNode) && docTaggingEnabled) {
            try {
                parentNode.insertBefore(structuredDocumentTag, para);
                structuredDocumentTag.appendChild(para);
            } catch (Exception ex) {
                throw new CustomException(SDT_INSERTION_ERROR_MESSAGE.formatted(ex.getMessage()), null);
            }
        }
    }

    public void makeParaChildOfSDTSectionParsing(CustomNode customNode, StructuredDocumentTag structuredDocumentTag) {
        Paragraph para = customNode.getParaNode();
        var parentNode = para.getParentNode();
        if (Objects.nonNull(parentNode)) {
            try {
                parentNode.insertBefore(structuredDocumentTag, para);
                structuredDocumentTag.appendChild(para);

                if(!customNode.isLastNodeInSection()) { //if it is the last node, the non-para nodes need not be inserted in the section.
                    var nonParaNodeList = this.getNonParaNodeListToAppend(para, structuredDocumentTag);
                    for (Node node : nonParaNodeList) {
                        parentNode.insertBefore(structuredDocumentTag, node);
                        structuredDocumentTag.appendChild(node);
                    }
                }

            } catch (Exception ex) {
                throw new CustomException(SDT_INSERTION_ERROR_MESSAGE.formatted(ex.getMessage()), null);
            }
        }
    }

    private List<Node> getNonParaNodeListToAppend(Paragraph paragraph, StructuredDocumentTag structuredDocumentTag){
        Node node = Objects.isNull(paragraph.getNextSibling()) ? structuredDocumentTag.getNextSibling() : paragraph.getNextSibling();
        if (Objects.isNull(node)) {
            return List.of();
        }
        List<Node> nonParaNodeList = new ArrayList<>();
        try {
            while (Objects.nonNull(node)) {
                if (node instanceof Paragraph && this.nodeUtil.isSkipNode((Paragraph) node, new Stack<>())) {
                    nonParaNodeList.add(node);
                    node = node.getNextSibling();
                    continue;
                }
                if (node.getNodeType() == NodeType.PARAGRAPH) {
                    break;
                }
                var parentNode = node.getParentNode();
                if (Objects.nonNull(parentNode)) {
                    if (node.getNodeType() == NodeType.TABLE) {
                        nonParaNodeList.add(node);
                    }
                }
                node = node.getNextSibling();
            }
        } catch (Exception ex) {
            throw new CustomException(SDT_INSERTION_ERROR_MESSAGE.formatted(ex.getMessage()), null);
        }
        return nonParaNodeList;
    }
}

In the attached document:
Tagged_doc.docx (17.8 KB)

Paragraph with text “NOW, THEREFORE, for and in consideration of the agreements set forth below, the MSA Contracting Parties agree as follows:” is showing content control in WPS but not in MS word.

@SATISHSATYAEESH

It sounds like you’re experiencing an issue where the content control (Structured Document Tag) is visible in WPS Office but not in Microsoft Word. This can occur due to several reasons related to how the content control is defined or how Microsoft Word interprets it.

Cause: The issue may stem from incorrect properties of the Structured Document Tag (SDT), compatibility of the SDT type with Microsoft Word, or improper document structure.

Solution: Here are steps to troubleshoot and potentially resolve the issue:

  1. Check SDT Properties: Ensure that the properties of the Structured Document Tag (SDT) are set correctly. For instance, check if the LockContentControl property is set to true, which might prevent deletion but should not affect visibility. Also, verify that the IsShowingPlaceholderText property is set correctly.

  2. SDT Type: Verify that the type of SDT you are creating is compatible with Microsoft Word. For example, types like RichText or PlainText should generally work, while more complex types may not render as expected.

  3. Document Structure: Ensure that the SDT is inserted correctly within the document structure. It should be a child of a valid parent node (like a paragraph or table). If the SDT is nested incorrectly, it may not display properly in Word.

  4. Testing with a Simple Example: Create a simple document with just one SDT to see if it appears in Word. This can help isolate whether the issue is with the specific document or the way SDTs are being created in your code.

  5. Update Aspose.Words: Ensure you are using the latest version of Aspose.Words, as updates often include bug fixes and improvements that could resolve compatibility issues.

Here’s a minimal code example to create a simple SDT:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Create a plain text SDT
StructuredDocumentTag sdt = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline);
sdt.Title = "Sample SDT";
sdt.Tag = "SampleTag";
builder.InsertNode(sdt);
builder.InsertParagraph();

doc.Save("SampleDocument.docx");

Next Steps: After trying these steps, check if the SDT appears in Microsoft Word. If the issue persists, please provide more details about the specific properties of the SDT or any error messages you might be encountering.

I hope this helps! Please let me know if you need further assistance.

@SATISHSATYAEESH Unfortunately, I cannot see the problem on my side.
WPS:

MS Word 2019:

Hi @alexey.noskov

I have using Microsoft® Word for Microsoft 365 MSO (Version 2506 Build 16.0.18925.20076) 64-bit and content control is not visible here.

@SATISHSATYAEESH Unfortunately, I do not see any problems in the produced document. Structure of the document is correct. In addition, structure of neighbor SDTs in your document is the same. So I do not see any reason why MS Word on your side does not show this particular SDT.

Hi @alexey.noskov

Attaching the complete document for reference and scrrenshot of WPS (version: 11.1.0.11723) and MS Word (version- Microsoft® Word for Microsoft 365 MSO (Version 2506 Build 16.0.18925.20076) 64-bit).

For the attached document at pageNo. 10:
In WPS : SDT with TITLE “b0acfac3-f989-475d-8603-636f6110fb50” starts from “WHEREAS, Service …” and ends at “…Contracting Parties agree as follows”.
In MS word: SDT with TITLE “b0acfac3-f989-475d-8603-636f6110fb50” stars from “WHEREAS, Service …” and ends at “…set forth in this MSA;”

Why this difference with same document at MS word and WPS.

Tagged_document.docx (251.3 KB)

MS Word:

WPS:

Hi @alexey.noskov

Any finding on this?

@SATISHSATYAEESH Unfortunately, I do not see any problems in the document structure. Here is XML representation of the mentioned SDT:

<w:sdt>
	<w:sdtPr>
		<w:alias w:val="b0acfac3-f989-475d-8603-636f6110fb50" />
		<w:tag w:val="b0acfac3-f989-475d-8603-636f6110fb50" />
		<w:id w:val="358523251" />
		<w:placeholder>
			<w:docPart w:val="DefaultPlaceholder_22675703" />
		</w:placeholder>
		<w:richText />
	</w:sdtPr>
	<w:sdtContent>
		<w:p w:rsidR="00F00FFF" w:rsidRPr="004519F5" w14:paraId="226D5C31" w14:textId="7C7F5D6A">
			<w:pPr>
				<w:pStyle w:val="Single" />
			</w:pPr>
			<w:r w:rsidRPr="004519F5">
				<w:t xml:space="preserve">WHEREAS, </w:t>
			</w:r>
			<w:r>
				<w:t>Service Provider</w:t>
			</w:r>
			<w:r w:rsidRPr="004519F5">
				<w:t xml:space="preserve"> and </w:t>
			</w:r>
			<w:r w:rsidR="00B50A41">
				<w:t>XYZ</w:t>
			</w:r>
			<w:r w:rsidRPr="004519F5">
				<w:t xml:space="preserve"> (collectively, the </w:t>
			</w:r>
			<w:r w:rsidR="00C51B44">
				<w:t>“</w:t>
			</w:r>
			<w:r w:rsidRPr="004519F5">
				<w:rPr>
					<w:u w:val="single" />
				</w:rPr>
				<w:t>MSA Contracting Parties</w:t>
			</w:r>
			<w:r w:rsidR="00C51B44">
				<w:t>”</w:t>
			</w:r>
			<w:r w:rsidRPr="004519F5">
				<w:t>) have engaged in extensive negotiations and discussions that have culminated in the formation of the relationship set forth in this MSA;</w:t>
			</w:r>
		</w:p>
		<w:p w:rsidR="00F00FFF" w14:paraId="7ED73E27" w14:textId="77777777">
			<w:pPr>
				<w:pStyle w:val="Single" />
			</w:pPr>
			<w:r>
				<w:t>NOW, THEREFORE, for and in consideration of the agreements set forth below, the MSA Contracting Parties agree as follows:</w:t>
			</w:r>
		</w:p>
	</w:sdtContent>
</w:sdt>

As you can see both paragraphs are in the same SDT. Looks like there is a bug in MS Word, so it displays the second paragraph outside the SDT.