DocumentVisitor Class duplicates images

Hi,

I have a word document resulting from a merger (Document.docx), which therefore always contains field codes (MERGEFIELD).

On this file I did CTRL+A, then CTRL+SHIFT+F9 to block (delete) the field codes, I saved-as in the file (Output Word.docx), this file is correct.

I wanted to automate this method with aspose using the DocumentVisitor class (Output Aspose.docx), the fields codes were deleted but the images were multiplied.

I can’t figure out where these images are coming from, or how to get around this problem with Aspose.

Can you look at where this problem is coming from?

I have attached an example.

Thank you Best regards.

element.zip (125.5 KB)

@ISIWARE You can achieve what you need using Document.UnlinkField method. This method does exactly what CTRL+A, then CTRL+SHIFT+F9 does in MS Word:

Document doc = new Document(@"C:\Temp\in.docx");
doc.UnlinkFields();
doc.Save(@"C:\Temp\out.docx");

Regarding your code, it is also required to add VisitShapeStart and VisitGroupShapeStart and remove these nodes if they are inside field code, like you do for Run nodes.

Thanks for the quick response, it works

1 Like