N8N Tools - PDF Generator icon

N8N Tools - PDF Generator

Generate PDFs using N8N Tools platform

Overview

This node generates PDF documents using the N8N Tools platform. It supports multiple ways to create PDFs:

  • Generate from HTML: Convert raw HTML content into a PDF.
  • Generate from Template: Use a predefined DOCX template populated with JSON data to produce a PDF.
  • Generate from URL: Capture a webpage by its URL and convert it into a PDF.

This node is useful for automating document generation workflows, such as creating reports, invoices, or marketing materials dynamically from HTML or templates, or archiving web pages as PDFs.

Practical Examples

  • Automatically generate a PDF invoice from an HTML template filled with customer data.
  • Create a PDF report from a DOCX template populated with analytics data.
  • Save a snapshot of a webpage as a PDF for record-keeping or offline viewing.

Properties

Name Meaning
Operation Choose the PDF generation method: "Generate from HTML", "Generate from Template", or "Generate from URL".
HTML Content Raw HTML string to convert into a PDF (used only when operation is "Generate from HTML").
Template Select or specify the ID of a DOCX template to use for PDF generation (used only for "Generate from Template").
Template Data JSON object with variables to populate the selected template (used only for "Generate from Template").
URL Webpage URL to convert into a PDF (used only for "Generate from URL").
Options Collection of additional settings:
- Filename Name of the generated PDF file (default: "document.pdf").
- Format Paper format: "A4", "A3", "Letter", or "Legal" (default: "A4").
- Orientation Page orientation: "portrait" or "landscape" (default: "portrait").
- Include Header Whether to include a header in the PDF (boolean).
- Include Footer Whether to include a footer in the PDF (boolean).
- Margin Top Top margin size (e.g., "1cm", "10px").
- Margin Bottom Bottom margin size.
- Margin Left Left margin size.
- Margin Right Right margin size.
- Print Background (Only for "Generate from URL") Whether to include background graphics in the PDF (boolean, default true).
- Wait Delay (ms) (Only for "Generate from URL") Time in milliseconds to wait before generating the PDF (default 3000).
- Emulated Media Type (Only for "Generate from URL") Media type to emulate: "screen" or "print" (default "screen").

Output

The node outputs an array of items, each containing:

  • json: Metadata about the generated PDF:

    • success: Boolean indicating if PDF generation succeeded.
    • filename: The name of the generated PDF file.
    • size: Size of the PDF in bytes.
    • operation: The operation used ("generateFromHtml", "generateFromTemplate", or "generateFromUrl").
    • Additional metadata about API usage credits and costs (credits used, remaining, cost in USD, operation cost, budget alerts/messages).
  • binary.data: The actual PDF file content as binary data, ready for further processing or saving.

Dependencies

  • Requires an API key credential for the N8N Tools platform to authenticate requests.
  • Uses HTTP requests to communicate with the N8N Tools API endpoints.
  • For template-based generation, the node fetches the DOCX template file from the API.
  • Uses the form-data package internally to send multipart form data when generating from templates.

Troubleshooting

  • Missing Template ID: When using "Generate from Template", the node throws an error if no template ID is provided. Ensure you select or enter a valid template ID.
  • API Authentication Errors: If the API key credential is invalid or missing, requests will fail. Verify your API key configuration.
  • No Response Body: If the API returns no PDF data, the node throws an error. This could indicate a server issue or malformed request.
  • Invalid Response Type: If the response body is not a buffer or string, the node cannot process it. Check API compatibility and network issues.
  • Timeouts or Delays: For "Generate from URL", insufficient wait delay might cause incomplete page rendering. Increase the "Wait Delay" property if PDFs are incomplete.
  • Continue on Fail: If enabled, the node will output error details per item instead of stopping execution.

Links and References

Discussion