HTML to PDF icon

HTML to PDF

Convert HTML content to PDF using wkhtmltopdf

Overview

This node converts HTML content or an HTML page URL into a PDF document using the wkhtmltopdf tool. It is useful for automating the generation of PDF files from web content or raw HTML, such as creating reports, invoices, or printable documents from dynamic HTML sources. Users can specify page size, orientation, margins, and other PDF options, and choose how the PDF output is returned (binary file, base64 string, or saved file path).

Use Case Examples

  1. Convert a dynamic HTML report into a PDF file and return it as a binary attachment for email sending.
  2. Generate a PDF from a public webpage URL and save the file locally for archival.
  3. Create a PDF from custom HTML content with specific page size and orientation for printing.

Properties

Name Meaning
HTML Content The raw HTML content to convert into a PDF document.
HTML URL The URL of the HTML page to convert into a PDF document.
Output Format How the generated PDF should be returned: as a binary file, base64 string, or saved file path.
Output Filename Custom filename for the PDF without extension. If empty, an auto-generated name is used.
Page Size The page size of the PDF document.
Orientation The page orientation of the PDF document.
Margin Top Top margin of the PDF page (e.g., 10mm, 1in, 20px).
Margin Right Right margin of the PDF page (e.g., 10mm, 1in, 20px).
Margin Bottom Bottom margin of the PDF page (e.g., 10mm, 1in, 20px).
Margin Left Left margin of the PDF page (e.g., 10mm, 1in, 20px).
Enable JavaScript Whether to enable JavaScript execution in the HTML before conversion.
Custom Options Additional command-line options for wkhtmltopdf, space-separated.
Wkhtmltopdf binary path Path to the wkhtmltopdf binary executable to use for conversion.

Output

Binary

The node can output the generated PDF as a binary file with MIME type 'application/pdf', including filename and extension metadata.

JSON

  • pdf - Base64 encoded PDF content when output format is base64.
  • size - Size of the generated PDF in bytes.
  • filename - Filename of the generated PDF file.
  • filePath - File system path where the PDF is saved when output format is 'filepath'.
  • fileName - Filename of the saved PDF file when output format is 'filepath'.

Dependencies

  • wkhtmltopdf binary executable

Troubleshooting

  • Error if neither HTML content nor HTML URL is provided: Ensure to provide at least one input source for conversion.
  • Errors related to wkhtmltopdf binary path: Verify the binary path is correct and accessible on the system.
  • Output format errors: Use only supported output formats ('binary', 'base64', 'filepath').
  • File write errors when saving PDF: Check file system permissions and available disk space.

Links

Discussion