htmlToPdf(filename, [html], [usePrintCss]) Last updated: 26. May 2025
API only function
Converts html to a PDF file using headless Chrome.
Parameters
Name | Type | Description |
---|---|---|
filename | string | Specify output filename. |
html (optional) | string | A string containing a table to convert from HTML to PDF. If not specified, the current output buffer (using the write method) will be used as HTML content. Note that to specify usePrintCss and not html, simply pass a null value here. |
usePrintCss (optional) | bool | Use the print media when creating PDF, default is false. |
Returns
PDF file in bytes.
Example
Code example (JS)
JS is normal JavaScript either running in the browser or on the Docly™ server.// Use the write function to write to the output buffer
write('<table>');
write('<tr><th>Column1</th><th>Column2</th></tr>'); // headers
write('<tr><td>Row1Value1</td><td>Row1Value2</td></tr>'); // row 1
write('<tr><td>Row2Value1</td><td>Row2Value2</td></tr>'); // row 2
write('</table>');
// This will produce a download of the file:
let pdf = docly.htmlToPdf("test.pdf");
return pdf;
// This will display the PDF file in the browser:
let pdf = docly.htmlToPdf();
setContentDisposition("inline", "test.pdf"); // Note: Overwrites the filename if specified before
return pdf;