PdfKit

PDFKit Node

Overview

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

Practical examples:

  • Convert a batch of images (e.g., scanned documents or photos) into a single PDF file for easy sharing or archiving.
  • Merge two separate PDF reports into one consolidated report.
  • Convert an Excel spreadsheet into a PDF for distribution or printing without requiring Excel software.

Properties

Name Meaning
Destination Key The binary key name under which the resulting PDF will be stored in the output item.
PDF Name The filename to assign to the generated PDF file.
First PDF Binary Field The binary field containing the first PDF file to merge (used only in "Merge PDFs" operation).
Second PDF Binary Field The binary field containing the second PDF file to merge (used only in "Merge PDFs" operation).
Keep Source PDFs Whether to retain the original source PDFs in the binary data after merging (boolean).

Output

The node outputs items with a binary property containing the generated PDF file under the specified destination key. The binary data includes the PDF content with the given filename (PDF Name property).

  • For Merge PDFs, the output binary contains the merged PDF combining pages from both input PDFs.
  • For Images to PDF, the output binary contains a PDF composed of all input images as pages.
  • For Excel to PDF, the output binary contains a PDF rendering of the selected worksheet from the Excel file.

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

Dependencies

  • Uses the pdf-lib library to handle PDF merging.
  • Uses pdfkit for creating PDFs from images and Excel data.
  • Uses image-size to determine image dimensions.
  • Uses exceljs to read Excel files and extract worksheet data.
  • Requires access to binary data buffers within n8n items.
  • No external API keys or services are required; all processing is done locally within the node.

Troubleshooting

  • Missing binary fields: If the specified binary field for PDFs or Excel files does not exist on the input item, the node throws an error indicating the missing field and lists available binary fields. Ensure the binary field names match exactly.
  • Invalid or corrupted PDFs/Excel files: Errors during merging or conversion often indicate invalid or corrupted input files. Verify that the input files are valid and not damaged.
  • Empty Excel sheets: Converting an empty worksheet to PDF results in an error. Confirm the selected sheet contains data.
  • Sheet selection errors: When specifying a sheet by name or index, ensure the sheet exists in the workbook. Indexing starts at 1.
  • Binary data absence: The node requires binary data on input items. If none is present, it throws an error.
  • Large files: Processing very large PDFs or Excel files may consume significant memory or time.

Links and References

Discussion