Puppeteer icon

Puppeteer

Automate browser interactions using Puppeteer

Overview

The Get PDF operation of the "Default" resource in this custom n8n Puppeteer node allows you to generate a PDF file from a web page. It uses Puppeteer (with optional stealth and human-typing plugins) to render the specified URL, apply various print and browser options, and output the resulting PDF as binary data. This is useful for automating website archiving, generating printable reports, invoices, or snapshots of dynamic web content.

Practical examples:

  • Automatically save invoices from a web portal as PDFs.
  • Archive web pages for compliance or record-keeping.
  • Generate formatted reports from dashboards or analytics tools.

Properties

Below are the supported input properties for the Get PDF operation:

Display 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 PDF data will be stored. Required.
Page Ranges String Specific pages to include in the PDF (e.g., "1-5, 8, 11-13"). Optional.
Scale Number Scale factor for rendering (0.1–2). Controls the size of the content in the PDF. Default: 1. Required.
Prefer CSS Page Size Boolean If true, uses any CSS @page size set by the page over width/height/format options. Default: true. Required.
Format Options Paper format (e.g., Letter, A4). Only used if "Prefer CSS Page Size" is false and height/width are not set. Default: Letter.
Height String Custom paper height (e.g., "11in", "297mm"). Used if "Prefer CSS Page Size" is false. Optional.
Width String Custom paper width (e.g., "8.5in", "210mm"). Used if "Prefer CSS Page Size" is false. Optional.
Landscape Boolean Whether to print in landscape orientation. Default: true. Required.
Margin Collection Set margins for top, bottom, left, right. Optional.
Display Header/Footer Boolean Show header and footer in the PDF. Default: false. Required.
Header Template String HTML template for the header (only if header/footer display is enabled). Optional.
Footer Template String HTML template for the footer (only if header/footer display is enabled). Optional.
Transparent Background Boolean Hide default white background for transparency. Default: false. Required.
Background Graphics Boolean Include background graphics in the PDF. Default: false. Required.
Query Parameters FixedCollection Additional query parameters to append to the URL. Optional.
Options Collection Advanced browser and Puppeteer settings (see below). Optional.

Notable sub-options under "Options":

  • Batch Size: Number of pages to process simultaneously.
  • Browser WebSocket Endpoint: Connect to an existing browser instance.
  • Emulate Device: Emulate a specific device profile.
  • Executable path: Path to the browser executable.
  • Extra Headers: Add custom HTTP headers.
  • File Name: File name for the binary output.
  • Launch Arguments: Extra command-line arguments for the browser.
  • Timeouts: Navigation and protocol timeouts.
  • Page Caching, Headless mode, Stealth mode, Proxy Server, etc.: Various browser behaviors.

Output

The node outputs an item with the following structure:

{
  "binary": {
    "<Property Name>": {
      // Binary PDF data, accessible via the specified Property Name
      "data": "<base64-encoded PDF>",
      "fileName": "<optional file name>",
      "mimeType": "application/pdf"
    }
  },
  "json": {
    "headers": { /* HTTP response headers from the page load */ },
    "statusCode": <HTTP status code>,
    "url": "<final URL after navigation>"
  }
}
  • The PDF file is available in the binary field under the key specified by Property Name.
  • The json field contains metadata about the request, such as headers, status code, and final URL.

Dependencies

  • External Services: None required unless using a remote browser (via Browser WebSocket Endpoint).
  • API Keys: Not required for basic usage, but may be needed if accessing protected web pages.
  • Node.js Packages: Uses puppeteer-extra, puppeteer-extra-plugin-stealth, puppeteer-extra-plugin-human-typing, and puppeteer.
  • n8n Configuration: No special configuration required unless running in a restricted environment (e.g., Docker containers may require additional launch arguments).

Troubleshooting

Common issues:

  • Invalid URL: If the provided URL is malformed, the node will return an error indicating "Invalid URL".
  • Navigation Timeout: If the page takes too long to load, you may see a timeout error. Adjust the "Timeout" option as needed.
  • Request failed with status code X: If the target page returns an HTTP error (e.g., 404, 500), the node will report this.
  • Failed to launch/connect to browser: Indicates issues with Puppeteer setup, browser installation, or connection parameters.
  • Custom script must return an array of items: (If using scripting features) Returned value must be an array.

How to resolve:

  • Double-check the URL and ensure it is reachable.
  • Increase the timeout values if dealing with slow-loading pages.
  • Ensure the browser dependencies are installed and accessible, especially in containerized environments.
  • For authentication-protected pages, use the appropriate headers or login flows.

Links and References

Discussion