I used aspose to generate docx file. But, there are still content controls on images, text, tables,…
I wanna to remove all content controls, but keep content. For exanple, I wanna remove content control on an image but keep the image.
How aspose word do that? Please give me code example.
Thanks for your inquiry.
You can use following code snippet to remove SDTs from your document.
private void RemoveSdt(Document doc)
{
// Get collection of SDT from the document
NodeCollection nodes = doc.GetChildNodes(NodeType.StructuredDocumentTag, true, true);
// Loop while there is SDT in the document
while (nodes.Count> 0)
{
StructuredDocumentTag sdt = (StructuredDocumentTag) nodes[0];
// Get parent node of SDT.
// We should move all content from SDT to its parent to preserve documents content.
CompositeNode parent = sdt.ParentNode;
// Loop throuht all nodes inside SDT and move its convent to parent node
while (sdt.HasChildNodes) parent.InsertBefore(sdt.FirstChild, sdt);
// Remove SDT.
sdt.Remove();
}
}