We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Is there any chance that Aspose.Words now supports JavaScript Execution when converting from HTML to DOCX/PDF?


Thank you for letting us know that Aspose.HTML now supports JavaScript Execution. I have been testing it out, and while I see the JavaScript Execution is working, I am getting different output results from converting HTML to DOCX in Aspose.HTML than I am in Aspose.Words. The resulting DOCX in Aspose.Words is formatted correctly and does not add in Highlighting Annotations for highlighted text. That is the desired output. Is there any chance that Aspose.Words now supports JavaScript Execution when converting from HTML to DOCX/PDF?



Your inquiry has been moved to the Aspose.Words category where you will assisted accordingly.

@InfoEdGlobal Currently, Aspose.Words mimics MS Word behavior, which does not support JavaScript execution.
Could you please attach sample document with JavaScript features you would like Aspose.Words to support? We will investigate the document and consider possibility of adding such feature n one of future versions.

Hello, I have attached a few documents and will try to explain the requirements.

In the TestHTMLTemplateJS.7z file, there is a TestHTMLTemplateJS.htm file. This is the file that ultimately needs to be converted to a DOCX while executing Javascript.

asposeWordsDocx.docx was created using Aspose.Words with just a basic open and save as DocX. The resulting DOCX is the desired output, however, the javascript within the HTML file is not executed. The code used is the following

Dim asposeWords As New Words.Document("C:\InfoEdSVN\Internal\Alpha15\TestHTMLTemplateJS.htm")

asposeHtmldocx.docx was created using Aspose.HTML. Using this, javascript is executed, and the output looks ok, but the main issue is that the text is basically split out into objects. Notably, the highlighted text as turned into essentially a yellow rectangle / word shape. This does not happen with Aspose.Words. It is a requirement for a clients to remove the text (and the corresponding highlighting) and input their own text. It is very difficult to do this with the objects that get created instead of just plain text. The code to generate this docx is the following:

    Dim margin As New Html.Drawing.Margin(36, 45, 36, 45)
    Dim docRenderingOptions As New Html.Rendering.Doc.DocRenderingOptions
    docRenderingOptions.PageSetup.AnyPage = New Html.Drawing.Page(margin)
    Using device As New Html.Rendering.Doc.DocDevice(docRenderingOptions, "C:\InfoEdSVN\Internal\Alpha15\AsposeHtmldocx.docx")
        Using htmlrenderer As New Html.Rendering.HtmlRenderer
            Using htmlDocument As New Html.HTMLDocument("C:\InfoEdSVN\Internal\Alpha15\TestHTMLTemplateJS.htm")
                htmlrenderer.Render(device, htmlDocument)
            End Using
        End Using
    End Using

Please let me know how I can achieve the desired results. Again, I need the javascript to be executed from the html file, but I want the output to be what I get from Aspose.Words (actual text instead of objects and shapes).

Let me know if you have questions about the requirements.

Thank you,

TestHTMLTemplateJS.7z (4.1 KB)
asposeWordsDocx.docx (25.8 KB)
AsposeHtmldocx.docx (68.5 KB)

@InfoEdGlobal Thank you for additional information. I have logged the feature request as WORDSNET-24368. However, it is not likely we will support this feature in Aspose.Words itself. In your case you need to get rendered HTML (after executing JajaScript) and then load it into Aspose.Words DOM.
@asad.ali Please also log feature request in Aspose.HTML to provide HTML Renderer to allow getting rendered HTML from source HTML after executing JavaScript in it.