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 ?
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.
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");