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

The node converts HTML content into a PDF document. It supports multiple input formats for the HTML source, including binary data from previous nodes, base64-encoded strings, raw HTML code, or a URL pointing to an HTML file. Users can customize the output PDF's layout, page size, margins, scaling, and visual options such as printing background graphics and displaying headers/footers.

This node is beneficial in scenarios where automated generation of PDFs from dynamic or static HTML content is required, such as generating reports, invoices, or printable documents from web content or user input within an n8n workflow.

Example use cases:

  • Convert a webpage (via URL) into a PDF report.
  • Transform raw HTML code created dynamically into a downloadable PDF.
  • Use binary HTML files from previous processing steps and convert them to PDFs with custom formatting.

Properties

Name Meaning
Input Data Type Method to provide the HTML content:
- Binary Data: Use HTML file from previous node (binary data)
- Base64 String: Provide HTML content already encoded in base64
- HTML Code: Write raw HTML code manually
- URL: Provide URL to HTML file to download and convert
Binary Property Name Name of the binary property containing the HTML file (used only if Input Data Type is Binary Data)
Base64 HTML Content The HTML content already encoded in base64 format (used only if Input Data Type is Base64 String)
HTML Code Raw HTML code entered manually; will be converted automatically to base64 (used only if Input Data Type is HTML Code)
HTML URL URL to the HTML file to convert (used only if Input Data Type is URL)
HTML File Name Source HTML file name with .html extension
Index File Path Optional index file path when the input file 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, 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) or not (false)
Display Header Footer Boolean flag to display header and footer in the PDF (true) or not (false)
Output File Name Desired filename for the generated PDF file
Binary Data Output Name Custom name for the binary data field in the node's output

Output

The node outputs the generated PDF as binary data under a configurable binary property name (default is data). The JSON output contains metadata about the operation and references the binary PDF file. The binary data represents the complete PDF document ready for saving, further processing, or sending.

Dependencies

  • Requires access to an external service or library capable of converting HTML content to PDF format.
  • No explicit API keys or credentials are mentioned in the provided code snippet, but the node likely depends on an underlying PDF conversion service integrated within the environment.
  • Proper network access is needed if using the URL input option to fetch remote HTML files.

Troubleshooting

  • Common issues:
    • Invalid or inaccessible URL when using the URL input type may cause failures in downloading the HTML content.
    • Incorrect base64 encoding or malformed HTML code can lead to conversion errors or corrupted PDFs.
    • Specifying unsupported page formats or invalid margin values might result in unexpected PDF layouts.
  • Error messages:
    • Errors related to fetching the URL usually indicate network issues or incorrect URLs.
    • Conversion errors often point to invalid input data or unsupported HTML features.
  • Resolutions:
    • Verify URLs are correct and accessible.
    • Ensure base64 strings are properly encoded.
    • Validate HTML code syntax before conversion.
    • Use supported page sizes and margin units.

Links and References

Discussion