Gotenberg icon

Gotenberg

Convert HTML to PDF using Gotenberg API

HTML to PDF

AI-generated

Overview

This node converts HTML content into PDF documents using the Gotenberg API. It is designed to transform raw HTML, including embedded images, CSS, fonts, and other assets, into a well-formatted PDF file. This is useful in scenarios such as generating reports, invoices, or printable documents dynamically from HTML templates.

Typical use cases include:

  • Creating PDFs from custom HTML email templates.
  • Generating printable versions of web pages or dashboards.
  • Archiving HTML content as PDF for long-term storage.
  • Adding headers and footers with page numbers to generated PDFs.

Properties

Name Meaning
HTML Content The raw HTML markup to convert into a PDF document. You can reference images and other assets by filename within this HTML.
Additional Files Collection of additional asset files to include in the conversion:
- Image Files (PNG, JPG, GIF, etc.)
- CSS Files (stylesheets)
- Font Files (WOFF, TTF, etc.)
- Other Files (any other assets)
Paper Size The size of the paper for the PDF output. Options: A3, A4, A5, Legal, Letter.
Landscape Boolean flag to set the orientation of the PDF to landscape (true) or portrait (false).
Advanced Options Collection of advanced PDF generation settings:
- Emulated Media Type: print or screen
- Flatten PDF: whether to flatten the PDF layers
- Generate Tagged PDF: create accessible tagged PDF
- Margins: custom margins in inches (top, bottom, left, right)
- Metadata: JSON object for PDF metadata (e.g., author, title)
- Page Ranges: specify which pages to print (e.g., "1-5,8,11-13")
- PDF/A Format: archival PDF format options (None, PDF/A-1b, PDF/A-2b, PDF/A-3b)
- PDF/UA Accessibility: enable universal accessibility features
- Print Background: include background graphics
- Scale: scale factor for rendering (0.1 to 2.0)
- Single Page: render entire content on one page
- Wait Delay: seconds to wait before conversion (useful for JavaScript-heavy pages)
Header & Footer Collection to add custom HTML content for page header and footer. Supports placeholders for page numbers (<span class="pageNumber"></span>) and total pages (<span class="totalPages"></span>).

Output

The node outputs binary data representing the generated PDF file:

  • The json field contains the original input JSON data passed through unchanged.
  • The binary.data field contains the PDF file data encoded appropriately for n8n binary handling.
  • The filename is typically document.pdf.
  • The MIME type is application/pdf.

If multiple files are merged or split, the output may differ (e.g., a ZIP archive for split PDFs), but for the HTML to PDF operation, the output is a single PDF binary file.

Dependencies

  • Requires an external Gotenberg API service endpoint URL configured via credentials.
  • Requires an API key or authentication token credential to access the Gotenberg API.
  • No other external dependencies are needed; all processing is done via the Gotenberg API.

Troubleshooting

  • No binary data found for field: Ensure that the specified binary field names for additional files (images, CSS, fonts, etc.) exist in the input data and contain valid binary data.
  • Invalid HTML content: Malformed HTML may cause conversion errors or unexpected PDF output. Validate your HTML before conversion.
  • Timeouts or delays: For JavaScript-heavy pages, use the "Wait Delay" advanced option to allow scripts to finish before conversion.
  • API connection errors: Verify that the Gotenberg API base URL and credentials are correctly configured and reachable.
  • Unsupported paper size or options: Use only supported paper sizes and valid option values as defined in the properties.
  • Metadata JSON parsing errors: Ensure the metadata JSON is valid; otherwise, it will be ignored silently.

Links and References

Discussion