Overview
This node converts HTML content into a PDF document without relying on any external API. It uses an embedded headless Chrome browser to render the HTML and generate the PDF, making it suitable for workflows that require reliable, self-contained PDF generation from either raw HTML strings or web pages.
Common scenarios include:
- Generating invoices, reports, or tickets from HTML templates.
- Archiving web pages as PDFs.
- Creating printable documents dynamically from HTML content within automation workflows.
For example, you can input an HTML string representing an invoice layout and get a PDF file output ready for emailing or storage. Alternatively, you can provide a URL of a webpage to convert that page directly into a PDF.
Properties
Name | Meaning |
---|---|
HTML Source | Source of the HTML content: either "HTML String" (direct HTML code) or "URL" (webpage link). |
HTML | The actual HTML content to convert (shown if "HTML String" is selected as source). |
URL | The URL to load and convert to PDF (shown if "URL" is selected as source). |
Output Format | Format of the output: "PDF File" (binary PDF data) or "Base64 String" (PDF encoded in base64). |
PDF Options | Collection of options for PDF generation: |
- Format | Paper format: A4, A3, Letter, Legal, Tabloid. |
- Landscape | Boolean to set landscape orientation (true/false). |
- Margin Top | Top margin size (e.g., "10px", "1cm"). |
- Margin Right | Right margin size. |
- Margin Bottom | Bottom margin size. |
- Margin Left | Left margin size. |
- Print Background | Whether to print background graphics (true/false). |
Output
The node outputs an array of items corresponding to each input item processed. Each output item contains:
json
:success
: boolean indicating if PDF generation succeeded.size
: size of the generated PDF in bytes.data
: (only if output format is Base64) the PDF content encoded as a base64 string.
binary
(only if output format is PDF File):pdf
: binary data of the generated PDF file with MIME typeapplication/pdf
.
This allows downstream nodes to either handle the PDF as a file (for saving or sending) or as a base64 string (for embedding or further processing).
Dependencies
- Requires Puppeteer, which internally uses a headless Chrome browser to render HTML and generate PDFs.
- The environment where n8n runs must have Chrome installed or be able to run Chromium bundled with Puppeteer.
- No external API keys or services are needed since PDF generation is done locally.
Troubleshooting
- Chrome browser not found: If the error message indicates Chrome is missing, ensure Chrome or Chromium is installed on your system or included in your container image.
- Failed to launch Chrome browser: This may occur due to insufficient permissions or sandboxing issues. Running n8n with administrator privileges or adjusting system permissions might resolve this.
- Timeouts or network errors when loading URLs: Ensure the URL is accessible from the n8n environment and that there are no firewall or DNS issues.
- Large or complex HTML causing performance issues: Simplify HTML or increase resource limits if possible.