At least, until Aspose for Java v19.6, the Document.getPackageCustomParts returned the web extensions within the document as a CustomPart. We used that code to iterate the custom parts and remove a specific web extension.
Now, v20.4 returns no results for the same scenario, we know there is a new WebExtension API (getWebExtensionTaskPanes) that should allow us to implement similar functionality, but we are wondering if this change in getPackageCustomParts is expected or is a broken functionality.
Enclosed you can find an example.
sample.zip (20.3 KB)
Please use the following code example to get the WebExtension and CustomXmlPart. Hope this helps you.
Document doc = new Document(MyDir + "test-webextension.docx"); System.out.println(doc.getWebExtensionTaskPanes().getCount()); WebExtension webExtension = doc.getWebExtensionTaskPanes().get(0).getWebExtension(); byte data = doc.getCustomXmlParts().get(1).getData(); String xml = new String(data, StandardCharsets.UTF_8); System.out.println(xml);
@tahir.manzoor, Thank you for your help, but I am afraid that code is for CustomXmlPart, in my case I need access to the CustomPart elements.
A small description about CustomPart is available here: https://reference.aspose.com/words/java/com.aspose.words/CustomPartCollection
// Open a document that contains custom parts
// CustomParts are arbitrary content OOXML parts
// Not to be confused with Custom XML data which is represented by CustomXmlParts
// This part is internal, meaning it is contained inside the OOXML package
Additionally, neither WebExtension or TaskPane classes have a getData function, similar to the one in CustomXmlPart or CustomPart
The following code example does not returns 0 value for web extension. You can read the values of web extension (of your document i.e. word\webextensions\webextension1.xml) using WebExtension class members. Please unzip your word document and check the detail of web extension.
Document doc = new Document(MyDir + "test-webextension.docx"); System.out.println(doc.getWebExtensionTaskPanes().getCount());
Yes, that code works. My issue is not with the new WebExtension API, it works as you said, my concern is about the Document.getPackageCustomParts() doesn’t work anymore in the way it used to work at least until 19.6 version.
Please use the latest version of Aspose.Words for Java 20.5 and use WebExtension class as suggested in my previous post.