Free Support Forum - aspose.com

Responsive HTML result for Word document

Dear Aspose support,

we are using Aspose.Word to convert Word documents uploaded by our customers to HTM to display the content in our business web application directly inside an IFRAME element.

To enhance the visual experience for our customers it would be great if the HTML would be responsive to the current width of the IFRAME. Unfortunately the resulting HTML from Aspose contains absolute size values (in pt).

  1. Is there any possibility to have Aspose create such responsive (relative) sizes?

  2. And: is there a possibility to add own CSS or JavaScript to the resulting HTML (without the need to parse it on our own)?

The Aspose API we are using: Aspose-Words for Java 17.5

Code example (very straight forward):

@Override
public void convertToHtml(InputStream inputStream, OutputStream outputStream) {
    try {
        Document doc = new Document(inputStream);
        doc.save(outputStream, saveOptions);
    } catch (Exception e) {
        LOG.error("Convert to html failed with exception", e.getMessage());
        throw new ConversionException("Convert to html failed", e);
    }
}

and

 public SaveOptions createSaveOptions() {
    HtmlFixedSaveOptions options = new HtmlFixedSaveOptions();
         options.setExportEmbeddedImages(true);
         options.setExportEmbeddedCss(true);
         options.setExportEmbeddedFonts(true);
         options.setExportEmbeddedSvg(true);
         return options;
     }

Document types: DOC, DOCX and RTF

Kind regards,
Stefan Raubal

@stefan.raubal

Thanks for your inquiry. We will appreciate it if you please share your sample input, output and expected output documents here. We will look into these and will guide you accordingly.

Furthermore, in reference to your requirement to add your own CSS/Java Script to resultant HTML, please share some more details along with sample documents. We will investigate your requirements and will update you accordingly.

Best Regards,

@tilal.ahmad,

thank you for your reply.

I have problems providing a concrete input and output document.
When you take the output that I provided with https://forum.aspose.com/t/math-equations-symbol-font-not-correctly-converted-problem-only-in-internet-explorer/27628 you can see that it contains absolute sized content:
e.g. <div class="awdiv awpage" style="width:595.35pt; height:841.95pt;">...</div>

Instead of such absolute sizes with “pt” we would be interested in relative values using “%” or a similar CSS technique.

That’s why I also asked about adding custom styling or scripting to the content (in the form of a or tag inside the element. Providing an external URL for the script or the style would also be a solution.
Using this approach we might be able to use our own JavaScript/styling to adopt the widths and locations of the elements in the HTML document.

I hope this description was helpful.

Kind regards,
Stefan Raubal

@stefan.raubal

Thanks for sharing additional information. I am afraid your requested feature is not supported at the moment. For adding customer styling you may search and replace styles in HTML. However, we have logged a ticket WORDSNET-15577 in our issue tracking system for relative measurement support in HTML. We will keep you updated about the issue resolution progress.

We are sorry for the inconvenience.

Best Regards,

Thank you for your investigations and for creating an issue in your issue tracking system.
Looking forward to the solution.

Kind regards,
Stefan Raubal

1 Like

A post was split to a new topic: Responsive HTML result