PdfKit

PDFKit Node

Overview

This node provides PDF manipulation capabilities with three main operations: converting images to a PDF, merging two PDFs into one, and converting Excel spreadsheets to PDF format. It is useful in workflows where you need to generate or combine PDF documents dynamically from various input formats.

  • Convert Images To PDF: Takes multiple image files and compiles them into a single PDF document.
  • Merge PDFs: Combines two existing PDF files into one consolidated PDF.
  • Convert Excel To PDF: Converts an Excel worksheet into a formatted PDF document.

Practical examples:

  • Creating a PDF portfolio from a set of product images.
  • Merging contract pages stored as separate PDFs into a single file.
  • Generating reports by converting Excel data sheets into PDFs for distribution.

Properties

Name Meaning
Destination Key The binary key name under which the resulting PDF will be saved in the output item.
PDF Name The filename to assign to the generated PDF document.
First PDF Binary Field (mergePDFs) The binary field containing the first PDF file to merge.
Second PDF Binary Field (mergePDFs) The binary field containing the second PDF file to merge.
Keep Source PDFs (mergePDFs) Whether to retain the original source PDFs in the output binary data after merging.
Keep Images (imagesToPDF) Whether to keep the original images in the binary data after creating the PDF.
Excel Binary Field (xlsxToPDF) The binary field containing the Excel file to convert.
Include Headers (xlsxToPDF) Whether to include column headers from the Excel sheet in the PDF output.
Sheet Name/Index (xlsxToPDF) The name or index of the Excel worksheet to convert (e.g., "1" for first sheet).
Keep Excel File (xlsxToPDF) Whether to keep the original Excel file in the binary data after conversion.

Output

The node outputs items with a binary property containing the generated PDF file under the specified destination key. The PDF file is named according to the provided PDF Name property with a .pdf extension.

  • For imagesToPDF, the output PDF contains all input images as pages.
  • For mergePDFs, the output PDF contains all pages from both input PDFs combined sequentially.
  • For xlsxToPDF, the output PDF contains a formatted representation of the selected Excel worksheet, including optional headers and pagination.

If configured to keep source files (images, PDFs, or Excel), those remain in the binary data alongside the new PDF.

Dependencies

  • Uses the pdfkit library to create PDFs from images and Excel data.
  • Uses pdf-lib to load and merge existing PDF files.
  • Uses image-size to determine dimensions of images.
  • Uses exceljs to read Excel files and extract worksheet data.
  • Requires binary data inputs for images, PDFs, or Excel files depending on operation.
  • No external API keys or services are required; all processing is local within the node.

Troubleshooting

  • Missing Binary Data: Errors occur if expected binary fields (images, PDFs, Excel) are not present or incorrectly named. Verify that the binary field names exactly match those specified in the node properties.
  • Invalid PDF Files: When merging PDFs, corrupted or invalid PDF files cause errors. Ensure input PDFs are valid and not damaged.
  • Empty or Missing Excel Sheets: If the specified sheet name or index does not exist in the Excel file, or the sheet is empty, the node throws an error. Check sheet names/indexes carefully.
  • Large Files or Many Pages: Processing very large images, PDFs, or Excel sheets may consume significant memory or time. Consider splitting inputs or optimizing files.
  • Keep Source Options: If source files are kept, output binary size increases. Disable these options if not needed.

Common error messages:

  • "No binary data exists on item!": Input item lacks any binary data.
  • "First PDF field \"X\" does not exist on item!": The specified first PDF binary field is missing.
  • "Second PDF field \"X\" does not exist on item!": The specified second PDF binary field is missing.
  • "Worksheet \"X\" not found in the workbook.": The requested Excel sheet does not exist.
  • "The selected worksheet \"X\" is empty.": The chosen Excel sheet has no data.

Links and References

Discussion