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 file.
- 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 for media emulation and delay.
This node is useful for automating document generation workflows such as creating reports, invoices, or printable versions of web content. For example, you can generate a PDF invoice by providing an HTML template filled with order details or convert a marketing webpage into a PDF brochure automatically.
Properties
| Name | Meaning |
|---|---|
| HTML Content | The raw HTML string to convert into a PDF (required for "Generate from HTML" operation). |
| Options | Collection of settings affecting PDF output: |
| - Filename | Name of the generated PDF file (default: "document.pdf"). |
| - Format | Paper size format; 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). |
| - Include Footer | Whether to include a footer in the PDF (boolean). |
| - 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 (boolean, default: true). |
| - Wait Delay (ms) | (Only for "Generate from URL") Delay before generating PDF in milliseconds (default: 3000). |
| - Emulated Media Type | (Only for "Generate from URL") Media type to emulate; options: Screen, Print (default: Screen). |
Additional properties for "Generate from Template" operation (not requested but present):
- Template: Select or specify the template ID to use.
- Template Data: JSON data to populate the template variables.
Output
The node outputs an array of items, each containing:
json: Metadata about the generated PDF:
success: Boolean indicating if generation succeeded.filename: Name of the generated PDF file.size: Size of the PDF in bytes.operation: The operation performed ("generateFromHtml", "generateFromTemplate", or "generateFromUrl").creditsUsed,creditsRemaining: Numeric values indicating API credit usage.costUSD: Cost of the operation in USD as a string.operationCost: Additional cost info as string.budgetAlert,budgetMessage: Optional budget-related messages.
binary.data: The actual PDF file data encoded as binary, ready for further processing 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 generate PDFs.
- Uses Axios for HTTP communication and FormData for multipart uploads when generating from templates.
- No additional environment variables are required beyond the API key credential configuration.
Troubleshooting
Common issues:
- Missing or invalid API key credential will cause authentication failures.
- Providing invalid or empty HTML content or URL may result in errors or empty PDFs.
- Incorrect template ID or malformed JSON template data can cause template generation to fail.
- Network connectivity issues to the N8N Tools API endpoint will prevent PDF generation.
Error messages:
"PDF generation failed: <error message>"indicates a failure during the API call or processing."Unknown operation: <operation>"means an unsupported operation was selected."Template ID is required"occurs if no valid template ID is provided for the template operation.
Resolutions:
- Verify API key credential is correctly configured and active.
- Ensure input HTML, URL, or template data is valid and properly formatted.
- Check network access to the API endpoint.
- Use the "Continue on Fail" option to handle errors gracefully in workflows.
Links and References
- N8N Documentation
- N8N Tools Platform API (general reference) (Note: specific API docs not included in source)