PDF4me icon

PDF4me

Comprehensive PDF and document processing: generate barcodes, convert files, extract data, manipulate images, and automate workflows with the PDF4ME API

Actions80

Overview

This node operation converts HTML content into a PDF document. It supports multiple input formats for the HTML source, including binary data from a previous node, base64-encoded HTML content, raw HTML code entered manually, or a URL pointing to an HTML file. The node allows customization of the output PDF's layout, page size, margins, scaling, and display options such as printing background graphics and showing headers/footers.

This operation is useful in scenarios where you need to generate PDF reports, invoices, or documents dynamically from HTML templates or web pages. For example, you can convert an HTML invoice template filled with customer data into a PDF file ready for distribution, or convert a webpage snapshot into a PDF for archiving.

Properties

Name Meaning
Input Data Type Method to provide the HTML content:
- Binary Data (HTML file from previous node)
- Base64 String (HTML content already base64 encoded)
- HTML Code (raw HTML code entered manually)
- URL (link to HTML file)
Binary Property Name Name of the binary property containing the HTML file (used when Input Data Type is Binary Data)
Base64 HTML Content Base64-encoded HTML content string (used when Input Data Type is Base64 String)
HTML Code Raw HTML code entered manually; will be converted automatically to base64 (used when Input Data Type is HTML Code)
HTML URL URL to the HTML file to download and convert (used when Input Data Type is URL)
HTML File Name Source HTML file name with .html extension
Index File Path Optional index file path required if the input is a ZIP archive
Layout Orientation of the output PDF:
- Portrait (vertical)
- Landscape (horizontal)
Format Page size of the PDF, e.g., A4, A3, Legal, Tabloid, etc.
Scale Scaling factor for the content within the PDF, ranging from 0 to 0.8
Top Margin Top margin spacing (e.g., "40px", "2cm", "1in")
Bottom Margin Bottom margin spacing
Left Margin Left margin spacing
Right Margin Right margin spacing
Print Background Boolean flag to include background graphics in the PDF (true to print backgrounds, false otherwise)
Display Header Footer Boolean flag to show header and footer in the PDF (true to display, false to hide)
Output File Name Desired filename for the generated PDF file (default: "output.pdf")

Output

The node outputs the generated PDF file as binary data attached to the output item. The main output field is a JSON object that includes the binary property containing the PDF file data. This binary data can be used downstream in workflows for saving to disk, sending via email, or uploading to cloud storage.

If configured, the output file name is set according to the "Output File Name" property.

Dependencies

  • Requires access to an external service or library capable of converting HTML content to PDF format.
  • May require network access if the input type is URL to fetch the HTML content.
  • No explicit API keys or credentials are indicated in the provided code snippet, but the underlying conversion service might require authentication configured elsewhere in n8n.

Troubleshooting

  • Common issues:
    • Invalid or inaccessible URL when using URL input type may cause download failures.
    • Incorrect base64 encoding or malformed HTML code can lead to conversion errors.
    • Specifying unsupported page formats or invalid margin values might cause unexpected PDF layouts.
  • Error messages:
    • Errors related to fetching the HTML content (e.g., network errors) should be checked by verifying the URL and network connectivity.
    • Conversion errors often indicate problems with the input HTML content or unsupported features in the HTML.
  • To resolve issues, verify input data correctness, ensure URLs are reachable, and check margin and scale values are within allowed ranges.

Links and References

Discussion