HTML to PDF / DOCX / RTF Java converter library › Forums › PD4ML v3 Archived Forums (Read Only) › HTML/CSS rendering issues › Is JavaScript supported? › Re: Re: Is JavaScript supported?
We do not plan to natively support JavaScript in PD4ML. Originally PD4ML is not intended for web sites capture; it is to allow you to define PDF layouts with simple well-known languages – HTML/CSS.
In PD4ML use cases JavaScript could be only used to generate some portions of HTML content, as the most of JavaScript “power” (interactivity, animation etc) is not applicable or direct convertible to its target PDF format.
As a drawback JavaScript support would turn PD4ML into a bulky construct (adding JavaScript runtime, DOM structures) and requires quite a serious refactoring of the existing code.
There is a tricky workaround JavaScript-enabled pages. It work only in web scenarios to implement “convert to PDF” button for current page. After JavaScript is evaluated in a web browser and the layout is rendered, the actual dynamic HTML can be captured from the browser and passed to PD4ML.
I’ve attached a draft, which illustrates it. The form “action” attribute should point to a Java servlet, which takes “source” parameter value (HTML code) and converts it to PDF.