Skip to content

qie.convertHtmlToPdf

Signature: qie.convertHtmlToPdf(value)

Returns: byte[] pdfBytes - the converted PDF document

Convert a string, file, or input stream to a PDF document.

Note

The HTML content must be well-formed XML (or XHTML) using CSS 2.1 for layout and formatting. See this KB article for more information.

Parameters

Type Name Description Default
String, File, or InputStream value the value we are going to attempt to convert

Example

// convertHtmlToPdf Examples:
// Example: value as String
var htmlDocument =
`<!DOCTYPE html>
   <html lang="en">
   <head><title>Testing</title></head>
   <body>
   <h1>Hello There!</h1>
   <p>This page contains some text.</p>
   </body>
</html>`;

var pdfBytes = qie.convertHtmlToPdf(htmlDocument);


// Example: value as File
qie.writeFile(
   "/tmp/test-document.html",
   `<!DOCTYPE html>
   <html lang="en">
   <head><title>Testing File</title></head>
   <body>
   <h1>Hello From File!</h1>
   <p>This HTML came from a file.</p>
   </body>
   </html>`,
   true
);

var htmlFile = qie.newFile("/tmp/test-document.html");
var pdfBytesFromFile = qie.convertHtmlToPdf(htmlFile);


// Example: value as InputStream
var htmlInputStream = new java.io.ByteArrayInputStream(
   new java.lang.String(
      `<!DOCTYPE html>
      <html lang="en">
      <head><title>Testing Stream</title></head>
      <body>
      <h1>Hello From Stream!</h1>
      <p>This HTML came from an input stream.</p>
      </body>
      </html>`
   ).getBytes("utf-8")
);

var pdfBytesFromStream = qie.convertHtmlToPdf(htmlInputStream);