Hello, we have a script that uses aspose words to open, find and convert all shapes in a docx document to png.
In the attached document the second chart is being skipped. We noticed that if we delete the initial page break or the last table row in the document, the second chart will be converted/found.
Aspose_missing_shape_name.docx (35.1 KB)
Below is a code snippet should help replicate the issue.
load_options = LoadOptions()
load_options.temp_folder = temp_folder
_aspose_doc = aw.Document(filename, load_options)
i = 0
for node in _aspose_doc.get_child_nodes(aw.NodeType.SHAPE, True):
i+=1
print('DEBUG : ', i)
add_shape(node.as_shape())
for node in _aspose_doc.get_child_nodes(aw.NodeType.GROUP_SHAPE, True):
add_shape(node.as_group_shape())
with open(os.path.join(temp_dir, 'output.json'), 'w') as f:
f.write(json.dumps(_smart_objects))
@lbraguesdodoc
It seems that you are encountering an issue where the second chart in your DOCX document is not being processed correctly by your script using Aspose.Words. This can sometimes happen due to the structure of the document, particularly if there are elements like page breaks or tables that affect the layout.
Here are a few suggestions to troubleshoot and potentially resolve the issue:
-
Check Document Structure: Since you mentioned that deleting the initial page break or the last table row allows the second chart to be found, it may be worth examining how these elements are affecting the document’s flow. Ensure that the charts are not nested within other elements that might be causing them to be skipped.
-
Iterate Over All Nodes: Make sure that your script is correctly iterating over all nodes in the document. You can enhance your loop to include additional checks or logging to see if the second chart is being skipped due to a specific condition.
-
Use Shape and GroupShape: Your current implementation already includes loops for both Shape
and GroupShape
. Ensure that the second chart is not being treated as a group shape or is nested within another shape that might be causing it to be overlooked.
-
Debugging Output: Add more debugging output to your script to log the types and properties of each shape as you iterate through them. This can help identify why the second chart is not being processed.
-
Review Documentation: You may want to refer to the Aspose documentation on working with shapes and charts to ensure that you are using the API correctly. This can provide insights into any specific properties or methods that might be relevant to your issue.
If the problem persists after trying these suggestions, consider sharing a minimal reproducible example of your document and code on the forum for further assistance. This will help others to replicate the issue and provide more targeted support.
If you need more detailed examples or specific code snippets, feel free to ask!
@lbraguesdodoc Unfortunately, I cannot reproduce the problem on my side. The following code properly renders bot charts in your document:
doc = aw.Document("C:\\Temp\\in.docx")
i = 0
for node in doc.get_child_nodes(aw.NodeType.SHAPE, True):
i+=1
print('DEBUG : ', i)
node.as_shape().get_shape_renderer().save(f"C:\\Temp\\shape{i}.png", aw.saving.ImageSaveOptions(aw.SaveFormat.PNG))
I used the latest 25.4 version of Aspose.Words for Python for testing.
@alexey.noskov
We have created a dockerfile that replicates the issue, attached you can find the folder with the code needed to make the container, there is also a README file with instructions.
The Aspose.Words version used is the 24.8.0 but we also experimented with the 25.4, both replicate the issue.
aspose-test.zip (31.3 KB)
@lbraguesdodoc Thank you for additional information. The problem is still not reproducible on my side. Here are the produced output:
shape1.png (4.1 KB)
shape2.png (3.6 KB)
The problem on your side might occur because you are using Aspose.Words in evaluation mode and the document is truncated due to the evaluation version limitations.