[Regression in 14.12] importNode of some DrawingML nodes does no longer work

Hello,

We used the AsposeWord4Java library 13.8 and we recently tryied to used the latest version (14.12)
But it seems there is a huge regression about Document.importNode() on DrawingML nodes.

Please find a code example below (and input file attached) :

Document document = new Document("C:\tmp\AsposeBugDMWL.docx");
DrawingML node = (DrawingML)document.getChild(NodeType.DRAWING_ML, 0, true);
Document copyDocument = new Document();
Node copyNode = copyDocument.importNode(node, true);
copyDocument.getFirstSection().getBody().getFirstParagraph().appendChild(copyNode);

// Save the document but it can’t be opened using Word, the Word is corrupted …
copyDocument.save("C:\tmp\CopyAsposeBugDMWL.docx", SaveFormat.DOCX); 

// So load does not work it throws a FileCorruptedException 
// (it seems there is some missing namespaces declaration at start of document.xml) …
Document loadedCopyDocument = new Document("C:\tmp\CopyAsposeBugDMWL.docx");

This was working in 13.8 at least. But it no longer works in 14.12 …
Could you please fix it quickly ?

Hi Jean-Pascal,

Thanks for your inquiry. The following line of code return null value for your document when older version of Aspose.Words is used. In your case, the older version of Aspose.Words return GroupShape node. DrawingML node is CompositeNode now in latest version of Aspose.Words.

DrawingML node = (DrawingML)document.getChild(NodeType.DRAWING_ML, 0, true);

I have tested the scenario and have noticed that corrupt document is saved while using NodeImporter.ImportNode with empty document. For the sake of correction, I have logged this problem in our issue tracking system as WORDSNET-11369. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved. We apologize for your inconvenience.

As a workaround of this issue, please use the cloned document as shown in following code example.

Document document = new Document(MyDir + "AsposeBugDMWL.docx");
System.out.println(document.getChildNodes(NodeType.DRAWING_ML, true).getCount());
DrawingML node = (DrawingML)document.getChild(NodeType.DRAWING_ML, 0, true);
Document copyDocument = (Document)document.deepClone(false);
copyDocument.ensureMinimum();
System.out.println(copyDocument.getChildNodes(NodeType.DRAWING_ML, true).getCount());
Node copyNode = copyDocument.importNode(node, true);
copyDocument.getFirstSection().getBody().getFirstParagraph().appendChild(copyNode);
copyDocument.save(MyDir + "CopyAsposeBugDMWL.docx", SaveFormat.DOCX);
// So load does not work it throws a FileCorruptedException
// (it seems there is some missing namespaces declaration at start of document.xml) ...
Document loadedCopyDocument = new Document(MyDir + "CopyAsposeBugDMWL.docx");

Hi Jean-Pascal,

Thanks for your patience. This issue has been fixed in latest version of Aspose.Words. Please use the latest version of Aspose.Words for Java 15.5.0.

Please note that we removed the DrawingML from the Aspose.Words API. Please read the public API changes from here:
https://docs.aspose.com/words/java/aspose-words-for-java-15-2-0-release-notes/

Please use NodeType as Shape instead of DrawingML in your code.

The issues you have found earlier (filed as WORDSNET-11369) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.