Free Support Forum - aspose.com

Remove image from Picture Content Control

Hello,


How can i remove the image from a Picture Content Control but keep the control in the document ???

Thanks,
Kevin

Hi Kevin,


Thanks for your inquiry. The StructuredDocumentTag Class represents a structured document tag (SDT or content control) in a document. The picture contents control fills the content control with a single picture.

Please note that Aspose.Words tries to mimic the save behavior as MS Word do. You cannot remove image from picture contents control and keep the picture content control. If you remove image from picture contents control by using MS Word, the empty picture template will exist in the document. Please see the attached image for detail

However, you can set picture contents control data with an empty/template picture by using following code snippet.

<span style=“font-size:
10.0pt;font-family:“Courier New”;color:#2B91AF;mso-no-proof:yes”>Document<span style=“font-size:10.0pt;font-family:“Courier New”;mso-no-proof:yes”> document =
new Document(MyDir

  • “in.docx”);<o:p></o:p>

NodeCollection sdtNodes = document.GetChildNodes(NodeType.StructuredDocumentTag, true);

foreach (StructuredDocumentTag sdt in sdtNodes)

{

if (sdt.SdtType == SdtType.Picture)

{

DrawingML dml = (DrawingML)sdt.GetChild(NodeType.DrawingML, 0, true);

if (dml.HasImage)

{

dml.ImageData.SetImage(MyDir + "Empty Picture");

}

}

}