Overview
This node converts HTML content or a webpage URL into a PDF document. It supports two source types: direct HTML content input or fetching a webpage from a URL. The node generates a PDF with basic rendering, including text formatting and simple HTML elements, but does not support complex CSS. It is useful for automating PDF generation from web content or HTML snippets, such as creating reports, invoices, or documentation.
Use Case Examples
- Convert a simple HTML snippet containing a report summary into a PDF file.
- Fetch a webpage from a given URL and convert its content into a PDF document for offline reading or archiving.
Properties
| Name | Meaning |
|---|---|
| Source Type | Choose whether to convert HTML content directly or fetch a webpage from a URL for PDF conversion. |
| HTML Content | The HTML content to convert to PDF. Required if Source Type is 'HTML Content'. |
| URL | The URL of the webpage to convert to PDF. Required if Source Type is 'URL'. |
| PDF File Name | The name of the output PDF file. |
| Page Format | The paper format for the PDF document. |
| Orientation | Whether to use landscape orientation for the PDF (default is portrait). |
Output
Binary
The node outputs the generated PDF file as binary data under the 'data' property.
JSON
fileName- The name of the generated PDF file.mimeType- The MIME type of the output file, always 'application/pdf'.fileSize- The size of the generated PDF file in bytes.success- Indicates whether the PDF generation was successful.error- Error message if the PDF generation failed (present only if success is false).
Dependencies
- Uses 'node-fetch' to fetch webpage content from URLs.
- Uses 'pdfkit' to generate PDF documents.
- Uses 'cheerio' to parse and manipulate HTML content.
Troubleshooting
- If HTML content is empty when Source Type is 'HTML Content', the node throws an error indicating that HTML content cannot be empty.
- If URL is empty or fetching the URL fails (e.g., network issues or invalid URL), the node throws an error indicating the failure to fetch the URL.
- Complex CSS styles and advanced HTML features are not supported, so the PDF output may not fully match the original webpage's appearance.
- Ensure the input HTML is well-formed to avoid parsing issues.
- If the node is set to continue on fail, errors are returned in the output JSON with success set to false.