Sidebar
0 votes
2 views
ago by david-f-5427 (1.7k points)

QIE provides a built-in function to convert HTML to PDF. The HTML can be provided in a String, a Java File or a Java InputStream. For example:

var pdfBytes = qie.convertHtmlToPdf('<html><h1>Hello, World!</h1></html>');

The HTML must be well-formed XHTML, styled with CSS 2.1. Newer CSS features such as flexbox, grid and CSS variables are not supported. Images and stylesheets must use absolute URLs. If you build the HTML from message data, escape &, < and > in that data first. To make a PDF from other XML, such as a CDA document, transform it to XHTML first, for example with an XSLT.

The W3C page "Differences with HTML 4" (https://www.w3.org/TR/xhtml1/#diffs) is a short list of the rules: close every tag, write empty elements as <br/>, use lowercase names, quote attribute values, and escape & and <.

For styling, the W3C publishes the full CSS 2.1 spec (https://www.w3.org/TR/CSS21) and a beginner tutorial, "Starting with HTML + CSS" (https://www.w3.org/Style/Examples/011/firstcss).

If a conversion fails because of the markup, the W3C validator (https://validator.w3.org) can point out the problems. Paste your HTML on the "Validate by Direct Input" tab, expand "More Options", and choose "XHTML 1.0 Strict" from the "Doctype" dropdown. You can ignore the "Missing xmlns attribute" and missing head errors; QIE doesn't need them.

Please log in or register to answer this question.

...