Issue with set image alt text being lost

Hi,

There seems to be an issue we’ve encountered with alt text of images being lost while we’re merging documents. More specifically, we’re seeing this issue on things like auto-shapes inserted in Word 2013.

What we’ve observed is that there are images which when inserted in Word 2013 are enclosed in a set of mc:AlternateContent nodes. These basically have two options: one is to use a w:drawing tag if the new namespace word wordprocessing shapes is available, or to revert to a w:pict if it isn’t, as part of the mc:Fallback. What we’ve observed is that setAlternativeText API sets the alt text on the drawing component, but not the pict component; and when we essentially merge two documents, Aspose is stripping out the mc:AlternateContent nodes and retaining the w:pict, which doesn’t contain the alt text we want!

Could you please suggest a work-around that will help us retain any alt text we set to images? We’re utilizing Aspose Words 14.7 on a Linux 5 x64 environment running Java 7. Also attaching a document which has such a shape for your reference. Thanks!

Hi,
Sorry, I was not able to reproduce this issue at my end using the latest version of Aspose.Words for Java (i.e. 15.5.0). Can you please test with the latest version and share your complete code and a screenshot to reproduce the issue?
Best Regards,

Hi Muhammed,

The issue seems to be cropping up when we basically try to merge documents which were created on different version of Office. In our case, what we did was set the alt-text on images in a Word 2007 document, and on a Word 2013 document, and merged them using the Aspose merge API on the document object. What we’re observing is that for the shapes and group-shapes in the sections of the merged document corresponding to the Word 2013 content, there is no alt-text set. The analysis that we presented above is still correct in the sense that Aspose is setting the alt-text for the alternate content present as part of the drawingML tag, but not the shape node in the mc;Fallback. Could you please look into this issue? Thank you very much!

Also attaching the screenshot as requested.

Hi,
Thanks for the details. Can you please also share your input documents and code to make sure we are on the same page?
Best Regards,

Hi Muhammed,
The code is rather simple:

  1. For each document, iterate through all the images and shapes and set alt text.
NodeCollection dmlGShapes = doc.getChildNodes(NodeType.GROUP_SHAPE, true);
NodeCollection dmlShapes = doc.getChildNodes(NodeType.SHAPE, true);
NodeCollection dmlImages = doc.getChildNodes(NodeType.DRAWING_ML, true);
// iterating through group shapes:
for (GroupShape gml : (Iterable)dmlGShapes)
{
    dml.setAltText("Group shape alt text");
}
// write similar code for shapes and dml
  1. Merge documents:
Document src1, src2;
src1.appendDocument(src2, ImportFormatMode.KEEP_SOURCE_FORMATTING);

Also find attached the documents in question. Thanks!

Hi,
Thanks for the code and sample. We are investigating the issue and will update you soon.
Best Regards,

Hi,
Sorry for the delay.
In fact you are still testing with the older version. In latest versions, there is no DrawingML node and you can extract all shapes and DrawingML nodes using Shape class.
I used the following code with the latest version i.e. 15.6.0 at my end and was not able to see any issue. All shapes and group shapes are showing the Alt Text properly in MS Word as well as Aspose.Words. I have attached output document for your reference.

Document doc1 = new Document("Office2007_Doclet1.docx");
Document doc2 = new Document("Office2013_Doclet.docx");

System.out.println("Non group shapes Alt Text Doc1");
for (Shape shape : (Iterable)doc1.getChildNodes(NodeType.SHAPE, true))
{
    System.out.println(shape.getAlternativeText());
    shape.setAlternativeText("shape alt text");
}
System.out.println("Group shapes Alt Text Doc1");
for (GroupShape gshape : (Iterable)doc1.getChildNodes(NodeType.GROUP_SHAPE, true))
{
    System.out.println("Group" + gshape.getAlternativeText());
    gshape.setAlternativeText("Group shape alt text");
}
System.out.println("Non group shapes Alt Text Doc2");
for (Shape shape : (Iterable)doc2.getChildNodes(NodeType.SHAPE, true))
{
    System.out.println(shape.getAlternativeText());
    shape.setAlternativeText("shape alt text");
}
System.out.println("Group shapes Alt Text Doc2");
for (GroupShape gshape : (Iterable)doc2.getChildNodes(NodeType.GROUP_SHAPE, true))
{
    System.out.println("Group" + gshape.getAlternativeText());
    gshape.setAlternativeText("Group shape alt text");
}
doc1.appendDocument(doc2, ImportFormatMode.KEEP_SOURCE_FORMATTING);
System.out.println("Non group shapes Alt Text after merge");
for (Shape shape : (Iterable)doc1.getChildNodes(NodeType.SHAPE, true))
{
    System.out.println(shape.getAlternativeText());
}
System.out.println("Group shapes Alt Text after merge");
for (GroupShape gshape : (Iterable)doc1.getChildNodes(NodeType.GROUP_SHAPE, true))
{
    System.out.println("Group" + gshape.getAlternativeText());
}
doc1.save("Office_Doclet_merged.docx");

Please test with the latest version and let us know if you see any issue.
Best Regards,

Hi Muhammed,
We’ve been trying to get on to Aspose 15 series from what we currently are on (14.7) for a long - but we’ve been facing blocker issues in terms of critical bugs in all of your 15 releases so far. The current issue we’re seeing with the 15.6 release is an issue with the styles addCopy API wherein we’ve noticed that some fonts associated with certain styles are not getting copied into the document where we apply these styles. I shall test this out with the latest version, but please realize our difficulty in trying to do the upgrade. Also - what I’m curious about is the kind of merged document which has been generated after merging the office 2007 and 2013 documents - is it compatible with Office 2007? Thanks.

Hi,
We understand your concerns about the latest versions but the issues cannot be fixed in older versions and we must release new versions with fixes. You can report any issues in latest version (if a feature was working in older version and not working in latest one, it will be marked as regression)
As far as compatibility with MS Office 2007 is concerned, you can use the following code to optimize your documents for MS Office 2007.
doc.getCompatibilityOptions().optimizeFor(MsWordVersion.WORD_2007);
Best Regards,

Hi Muhammed,
One clarification we wanted to make is that when we see functionality issues in a newer version of Aspose that were working in an earlier version, are we supposed to explicitly state these are regression issues as opposed to bugs? The reason for bringing this up is to know whether regression issues are fixed earlier and on a higher priority as opposed to bugs so that we could ensure we move over to the newer versions of Aspose without any hitch.
Also - thank you for pointing out the compatibility options API, but we’re still seeing the issue with our current version of Aspose (14.7) in our environment. Thanks.

Hi,
Yes, if you see any feature working in older version and not working in newer version, you can report it as a regression. Regression issues have the highest priority and get fixed earlier than the other issues.
Best Regards,