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 three main operations:

  • Generate from HTML: Converts raw HTML content into a PDF.
  • Generate from Template: Uses a predefined DOCX template populated with JSON data to create a PDF.
  • Generate from URL: Converts a webpage at a given URL into a PDF, with options to control rendering details.

This node is useful for automating document generation workflows such as creating reports, invoices, or printable content dynamically from web pages, HTML snippets, or templates. For example, you could generate a PDF invoice by filling a template with customer data or convert a marketing webpage into a downloadable brochure.

Properties

Name Meaning
Options Collection of settings controlling PDF output:
- Filename Name of the generated PDF file (default: "document.pdf").
- Format Paper format for the PDF. Options: A4, A3, Letter, Legal (default: A4).
- Orientation Page orientation. Options: Portrait, Landscape (default: Portrait).
- Include Header Whether to include a header in the PDF (boolean, default: false).
- Include Footer Whether to include a footer in the PDF (boolean, default: false).
- Margin Top Top margin size (e.g., "1cm", "10px"; default: "1cm").
- Margin Bottom Bottom margin size (default: "1cm").
- Margin Left Left margin size (default: "1cm").
- Margin Right Right margin size (default: "1cm").
- Print Background (Only for Generate from URL) Whether to include background graphics in the PDF (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 during rendering. Options: Screen, Print (default: Screen).

Output

The node outputs an array of items, each containing:

  • json: Metadata about the generated PDF:

    • success: Boolean indicating if 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").
    • creditsUsed, creditsRemaining, costUSD, operationCost: Usage and cost information returned by the API.
    • budgetAlert, budgetMessage: Optional budget-related warnings or messages.
  • binary.data: The actual PDF file data encoded as binary, ready for further use or saving.

Dependencies

  • Requires an API key credential for the N8N Tools platform to authenticate requests.
  • Makes HTTP requests to the N8N Tools API endpoints to perform PDF generation.
  • Uses the axios library for HTTP communication and form-data for multipart uploads when generating PDFs from templates.

Troubleshooting

  • Common issues:

    • Missing or invalid API key credential will cause authentication failures.
    • Providing an invalid or missing template ID when generating from a template will throw an error.
    • Network issues or API downtime can cause request failures.
    • Incorrect JSON syntax in template data will result in empty or failed variable substitution.
  • Error messages:

    • "PDF generation failed: <error message>": General failure during PDF creation; check API credentials, input parameters, and network connectivity.
    • "Template ID is required": When generating from template, ensure a valid template ID is provided.
    • Unknown operation errors indicate misconfiguration of the operation parameter.
  • Resolutions:

    • Verify API key and endpoint configuration.
    • Validate all required inputs are provided and correctly formatted.
    • Use the node's "Continue On Fail" option to handle errors gracefully in workflows.

Links and References

Discussion