Overview
This n8n node uses Puppeteer (with optional stealth mode) to generate a PDF from a given web page URL. It allows extensive customization of the PDF output, including page size, margins, headers/footers, background graphics, and more. The node is ideal for automating the creation of PDFs from dynamic or static web content, such as generating reports, archiving web pages, or creating printable invoices directly from web applications.
Practical examples:
- Automatically save invoices or receipts from a web portal as PDFs.
- Archive web pages in PDF format for compliance or record-keeping.
- Generate printable reports from dashboards or analytics tools.
Properties
| Name | Type | Meaning |
|---|---|---|
| URL | String | The web address of the page to convert to PDF. Required. |
| Property Name | String | Name of the binary property where the resulting PDF data will be stored. Required. |
| Page Ranges | String | Specifies which pages to print, e.g., "1-5, 8, 11-13". Optional. |
| Scale | Number | Scales the rendering of the web page. Must be between 0.1 and 2. Default is 1. |
| Prefer CSS Page Size | Boolean | If true, uses any CSS @page size declared in the page over width/height/format options. |
| Format | Options | Paper format type (e.g., Letter, A4). Only used if "Prefer CSS Page Size" is false and height/width are not set. |
| Height | String | Sets the paper height (number or string with unit). Used if "Prefer CSS Page Size" is false. |
| Width | String | Sets the paper width (number or string with unit). Used if "Prefer CSS Page Size" is false. |
| Landscape | Boolean | Whether to print the PDF in landscape orientation. Default is true. |
| Margin | Collection | Set the PDF margins (top, bottom, left, right). Each margin is optional and specified as a string (e.g., "1cm"). |
| Display Header/Footer | Boolean | Whether to show header and footer in the PDF. Default is false. |
| Header Template | String | HTML template for the print header. Only used if "Display Header/Footer" is true. Supports special classes for dynamic values (date, title, url, etc.). |
| Footer Template | String | HTML template for the print footer. Only used if "Display Header/Footer" is true. Supports special classes for dynamic values. |
| Transparent Background | Boolean | If true, generates PDFs with transparency by omitting the default white background. |
| Background Graphics | Boolean | If true, includes background graphics in the PDF. |
| Query Parameters | Collection | Additional query parameters to append to the URL before loading the page. |
| Options | Collection | Advanced settings (see below): - Emulate Device - Executable path - Extra Headers - File Name - Launch Arguments - Timeout - Wait Until - Page Caching - Headless mode - Stealth mode - Proxy Server |
Notable Option Sub-properties
- Emulate Device: Emulates a specific device (e.g., iPhone, iPad) for rendering.
- Executable path: Path to the browser executable for Puppeteer.
- Extra Headers: Custom HTTP headers to send with the request.
- File Name: Sets the file name in the binary output.
- Launch Arguments: Additional command-line arguments for the browser instance.
- Timeout: Maximum navigation time in milliseconds (default: 30,000 ms).
- Wait Until: When to consider navigation succeeded (e.g., load, DOMContentLoaded).
- Page Caching: Enable/disable page-level caching.
- Headless mode: Run browser in headless mode (default: true).
- Stealth mode: Makes Puppeteer harder to detect as a bot.
- Proxy Server: Use a custom proxy configuration.
Output
- Binary Data:
- The generated PDF is returned as binary data under the property name specified by "Property Name".
- The binary data may include a file name if specified.
- JSON Metadata:
headers: HTTP response headers from the loaded page.statusCode: HTTP status code from the page load.
Example output structure:
{
"binary": {
"data": { /* PDF binary data */ }
},
"json": {
"headers": { /* HTTP headers */ },
"statusCode": 200
}
}
- The actual property name for the binary data is determined by the "Property Name" input.
Dependencies
- External Services: None required for basic operation.
- API Keys: Not required.
- Node.js Packages:
puppeteer-extrapuppeteer-extra-plugin-stealth(optional, for stealth mode)puppeteer
- n8n Configuration:
- Sufficient system resources to run a headless browser.
- If using a custom browser executable, ensure the path is accessible.
- If using a proxy, ensure network access and correct proxy configuration.
Troubleshooting
Common Issues:
- Request failed with status code XXX:
The target URL did not return a successful (200) HTTP status. Check the URL, network connectivity, authentication requirements, or possible blocks (e.g., CAPTCHA, login walls). - Timeout errors:
The page took too long to load. Increase the "Timeout" option or check the target site's performance. - Empty or corrupt PDF:
The page may have failed to render correctly, or the site uses anti-bot measures. Try enabling "Stealth mode" or adjusting headers/user-agent. - Browser launch failures:
Ensure Puppeteer can download or access the required browser binaries. If running in a restricted environment, specify an "Executable path".
Error Messages:
"Request failed with status code XXX": The node throws this error if the HTTP status is not 200 and "Continue On Fail" is not enabled. To resolve, verify the URL and that the page is accessible.- Browser-related errors (e.g., missing dependencies, permission issues): Check system logs and ensure all required libraries for Chromium are installed.