Skip to main content

Merge

Combines multiple PDF files into a single PDF document with various merging options including append mode, divider pages, and zip merging.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • PDF Paths - Array of PDF file paths to merge. Add multiple entries to merge multiple files.
  • Custom PDF Paths - Alternative method to provide PDF paths as a string array from message scope (e.g., ["file1.pdf", "file2.pdf"]).
  • PDF Path to Save - Output path where the merged PDF file will be saved.
note

You must provide PDF file paths either through PDF Paths fields or via Custom PDF Paths from the message scope.

Options

  • Divider Page - When enabled, inserts a blank divider page between each merged PDF document. Default is false.
  • Append - When enabled, appends the PDFs to an existing file at the output path if it exists. Default is false.
  • Zip Two Files Together - When enabled, interleaves pages from exactly two PDF files (e.g., 1a, 1b, 2a, 2b, ...). Default is false.
warning

When Zip Two Files Together is enabled:

  • Exactly two PDF paths must be provided
  • Divider Page and Append options are ignored

Output

This node does not produce any output variables. The merged PDF is saved to the specified path.

How It Works

The Merge node combines multiple PDF files into a single document. When executed, the node:

  1. Validates all input PDF paths and output path
  2. Determines the merge mode based on options
  3. Reads all input PDF files
  4. Applies the selected merge operation:
    • Standard merge: Combines all PDFs sequentially
    • Zip merge: Interleaves pages from two PDFs
    • Append mode: Adds to existing PDF if present
  5. Optionally inserts divider pages between documents
  6. Validates the resulting PDF
  7. Saves the merged PDF to the output path

Merge Modes

Standard Merge (Default)

Combines all PDF files in the order provided:

  • File1: pages 1-5
  • File2: pages 1-3
  • Result: pages 1-8 (File1 followed by File2)

Merge with Divider Pages

Inserts blank pages between each PDF:

  • File1: pages 1-5
  • Divider: blank page
  • File2: pages 1-3
  • Result: pages 1-9 (File1, blank, File2)

Append Mode

Adds PDFs to an existing file:

  • Existing PDF: pages 1-10
  • File1: pages 1-5
  • Result: pages 1-15 (Existing PDF + File1)

Zip Merge (Interleave)

Interleaves pages from exactly two PDFs:

  • File1: pages 1a, 2a, 3a
  • File2: pages 1b, 2b, 3b
  • Result: pages 1a, 1b, 2a, 2b, 3a, 3b

Use Cases

  • Document Consolidation: Combine multiple reports into a single PDF
  • Contract Assembly: Merge contract pages with attachments and exhibits
  • Report Generation: Combine cover page, content, and appendices
  • Batch Compilation: Merge processed PDF files into a master document
  • Book Creation: Combine chapters into a complete book
  • Invoice Compilation: Merge multiple invoices into a single file
  • Double-Sided Printing: Use zip merge to combine odd and even pages

Example Workflows

Basic Merge

  1. Collect multiple PDF files
  2. Use Merge node to combine them
  3. Save as a single consolidated PDF

Merge with Separators

  1. Enable "Divider Page" option
  2. Merge multiple PDFs
  3. Result has blank pages separating each original document

Append to Existing Document

  1. Enable "Append" option
  2. Merge new PDFs
  3. They are added to the end of existing PDF at output path

Zip Merge for Double-Sided Scans

  1. Scan odd pages: odd.pdf (pages 1, 3, 5)
  2. Scan even pages: even.pdf (pages 2, 4, 6)
  3. Enable "Zip Two Files Together"
  4. Result: properly ordered pages 1-6

Error Handling

The node will return specific errors in the following cases:

  • Empty PDF paths list
  • No PDF paths provided (neither array nor custom paths)
  • Invalid PDF path in the list
  • One or more PDF files not found
  • Empty or invalid output path
  • PDF files are encrypted or password-protected
  • "Zip Two Files Together" is enabled but not exactly 2 files provided
  • "Zip Two Files Together" conflicts with Append or Divider Page options
  • Insufficient permissions to read input files or write output file
  • Output PDF validation fails after merge

Usage Notes

  • All input PDF files must be accessible and readable
  • Original PDF files remain unchanged
  • The order of PDF files in the array determines the merge order
  • When using append mode, the output file is created if it doesn't exist
  • Zip merge only works with exactly two PDF files
  • For encrypted PDFs, decrypt them first using the Decrypt node
  • The merged PDF is validated after creation to ensure integrity
  • Divider pages are blank and use standard page size
  • Processing time increases with the number and size of PDFs

Tips for Effective Use

  • Order Matters: Arrange PDF paths in the desired merge order
  • Use Arrays: Build PDF path arrays dynamically for flexible merging
  • Validate First: Ensure all source PDFs are valid before merging
  • Test Small: Test merge operations with a few files first
  • Error Handling: Enable Continue On Error when merging many files
  • Naming Convention: Use descriptive output filenames like merged_report_${date}.pdf
  • Cleanup: Delete source files after successful merge if no longer needed
  • Size Consideration: Monitor output file size when merging many large PDFs
  • Divider Use Cases: Use divider pages when printing or for visual separation

Example Code

Dynamic Path Building

// Collect all PDF files from a directory
let pdfFiles = ["chapter1.pdf", "chapter2.pdf", "chapter3.pdf"];
msg.custom_paths = pdfFiles;

Conditional Merging

// Add optional appendix based on condition
let files = ["main.pdf"];
if (msg.includeAppendix) {
files.push("appendix.pdf");
}
msg.custom_paths = files;
  • Split: Split large PDFs before selective merging
  • Decrypt: Decrypt encrypted PDFs before merging
  • Optimize: Optimize the merged PDF to reduce file size