I have a web application that allows users to update word documents which I convert to HTML using Aspose.word.java version 21.8, and re-display in a browser. On the whole I find the conversion to HTML excellent.
The problem I came across is that in the HTML, images in the document are rendered inside svg first as
<svg>
<defs>
<image id="image006" xlink:href="data:image/jpeg;base64,...." />
</defs>...
and then displayed with:
<g>
<use xlink:href="#image006" width="200" ... />```
</g>
The issue I have is that if I have two word documents, each with an image in them, they can both render tags sharing the same id (e.g. “image006”). This means that if I render both documents on the browser at the same time, the of the second document references the image from the first document - since they both share the same image id
I am generating my HTML using
HtmlFixedSaveOptions options = new HtmlFixedSaveOptions();
options.setExportGeneratorName(true);
options.setExportEmbeddedCss(true);
options.setExportEmbeddedImages(true);
options.setExportEmbeddedSvg(true);
options.setExportEmbeddedFonts(true);
options.setShowPageBorder(true);
options.setPageMargins(0);
options.setPageHorizontalAlignment(HtmlFixedPageHorizontalAlignment.LEFT);
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
document.save(bos, options);
String s = new String(bos.toByteArray(), StandardCharsets.UTF_8);
out.append(s);
}
What I am looking for is a way to a prefix to the imageids so that the ids for my two document can be isolated from each other - similar I think to HTMLSaveOptions.setCssClassNamePrefix()
Here are two document, which generate imageids that are the same (and thus can’t be displayed on the same webpage)
I am doc 1.docx (100.5 KB)
I am doc 2.docx (75.1 KB)
Thanks,
Mark