Actions3
- Page Actions
Overview
This n8n custom node automates the process of rendering a web page in a headless browser and exporting it as a PDF. It uses Puppeteer to load the specified URL, apply various rendering options (such as viewport size, injected scripts/styles, headers, etc.), and then generates a PDF file of the rendered page. This is particularly useful for:
- Generating printable reports or invoices from web applications.
- Archiving web pages as PDFs for compliance or record-keeping.
- Automating the creation of documentation snapshots.
- Creating paginated, styled exports of dashboards or data visualizations.
Example use cases:
- Automatically save receipts from an online store as PDFs.
- Generate a PDF report from a dynamic dashboard after injecting custom styles/scripts.
- Archive a web page with specific user-agent and headers for legal purposes.
Properties
| Name | Type | Meaning |
|---|---|---|
| Target URL | string | The web address of the page to render and export as PDF. |
| Options | collection | Additional settings for page rendering (see below for sub-options). |
| └ Timeout | number | Maximum time (ms) to wait for the browser/page to load. |
| └ User-Agent | string | Custom user agent string for the browser session. |
| └ Element | string | CSS selector to wait for before proceeding (ensures element is loaded/visible). |
| └ Clip to Element? | boolean | If true, restricts screenshot/PDF to the selected element only. |
| └ Full Page? | boolean | If true, captures the entire scrollable page; otherwise, only the visible part. |
| └ Disable Javascript? | boolean | If true, disables JavaScript execution on the page. |
| └ Scroll To | string | CSS selector of an element to scroll into view before rendering. |
| └ Javascript Code | string | Custom JavaScript code to execute in the page context before rendering. |
| └ Headers | collection | HTTP headers to send with the request (array of name/value pairs). |
| └ Styles | collection | List of style tags (by URL or content) to inject into the page before rendering. |
| └ Scripts | collection | List of script tags (by URL or content) to inject into the page before rendering. |
| Viewport | collection | Settings for the browser viewport (window size, device emulation, etc.). |
| └ Width | number | Width of the viewport in pixels. |
| └ Height | number | Height of the viewport in pixels. |
| └ Scale Factor | number | Device pixel ratio (for high-DPI screens). |
| └ Is Mobile | boolean | Emulate mobile device if true. |
| └ Is Touchscreen | boolean | Emulate touchscreen if true. |
| └ Is Landscape | boolean | Use landscape orientation if true. |
| PDF Options | collection | PDF-specific options (only shown for PDF operation). |
| └ Display Header and Footer? | boolean | Show header/footer in the generated PDF. |
| └ Paper Format | options | Standard paper size (A4, Letter, etc.). |
| └ Landscape? | boolean | Render PDF in landscape orientation. |
| └ Print Background? | boolean | Include background graphics/colors in the PDF. |
| └ Page Range | string | Specify which pages to print (e.g., "1-5, 8, 11-13"). |
| └ Header Template | string | HTML template for the PDF header (supports named classes). |
| └ Footer Template | string | HTML template for the PDF footer (supports named classes). |
| └ Margins | collection | Set top, bottom, left, right margins for the PDF. |
Output
- binary.data: Contains the generated PDF file as binary data, typically named
page.pdf. - json:
url: The URL that was rendered.title: The title of the web page.metrics: Performance and resource usage metrics from the browser.evaluateResponse(optional): Result of any custom JavaScript code executed on the page.
Note: The primary output for this operation is the binary PDF file. The JSON output provides metadata about the rendering process.
Dependencies
- External Library: puppeteer (bundled)
- No API keys required.
- n8n Configuration: No special configuration needed, but the environment must allow running headless Chrome (Puppeteer). In some environments (e.g., Docker), you may need to ensure necessary dependencies for Chromium are installed.
Troubleshooting
Common Issues:
Timeouts:
- Error: "Navigation timeout of X ms exceeded"
Solution: Increase the "Timeout" option or check network connectivity to the target URL.
- Error: "Navigation timeout of X ms exceeded"
Page Not Loading / Blank PDFs:
- Possible causes: Incorrect URL, authentication required, or resources blocked by headers.
- Solution: Double-check the URL, add necessary headers/cookies, or test the URL in a regular browser.
Missing Elements:
- Error: "Element not found" or "waitForSelector timed out"
Solution: Ensure the correct CSS selector is provided and the element exists on the page.
- Error: "Element not found" or "waitForSelector timed out"
Binary Output Missing:
- Cause: If the page fails to render or Puppeteer crashes, the binary field may be empty.
- Solution: Check logs for errors, verify Puppeteer can run in your environment.
Chromium Launch Fails:
- Error: "Failed to launch the browser process!"
Solution: Make sure all system dependencies for Chromium are installed, especially in Docker or Linux environments.
- Error: "Failed to launch the browser process!"