Note: Visit our API Docs to learn more about the PDF Split endpoint.
Intelligent Document Assembly: Auto-Sort, Split & Merge PDFs into Professional Packages
What You'll Have When Done: Automatically turn unorganized document collections into clean, professional packages. This system sorts files by name, splits multi-page PDFs at logical breakpoints, inserts supporting materials in the correct locations, merges everything into one cohesive file—all without manual effort.
Prerequisites
Before you begin, make sure you have:
- A PDF.co API Key (Get yours here)
- An email inbox with IMAP access (to trigger document collection)
- A Google Drive account with OAuth2 credentials in n8n
- A Google Drive folder for saving completed packages
- An n8n instance (cloud or self-hosted)
- PDF documents that follow a structured naming convention (Download Sample PDFs)
Quick Start Options
Option A: I Want It Working Now
- Import this workflow template and sample files → Download Workflow Files
- Connect your IMAP, Google Drive, and PDF.co accounts
- Define naming conventions and split rules
- Test with sample document collection
- Activate and run
Option B: I Want to Build It Step-by-Step
Follow the 10-step guide below to create the automation from scratch.
What This Automation Does (Overview)
- Monitors your inbox for a new “Invoice Package” email
- Sorts attached documents by filename
- Splits complex multi-page documents at defined breakpoints
- Insert supporting documents
- Reassembles everything in the perfect sequence
- Applies a dynamic status stamp
- Uploads the final PDF to Google Drive
Step 1: Trigger Document Collection Processing
Node: Email Trigger IMAP
Settings:
- Mailbox Name:
INBOX
- Action:
Mark as Read
- Download Attachments:
True
- Custom Email Rules:
["UNSEEN", ["SUBJECT", "Invoice Package"]]
Success Looks Like: The workflow is triggered when a new or unread email with the subject “Invoice Package” arrives.
Step 2: Extract and Analyze Document Collection
Node: Code (JavaScript)
Settings: Use the provided JavaScript code to standardize documents from any source. Download JavaScript Code here
Success Looks Like: Each document is transformed into a workflow item, complete with metadata including its filename, and type.
Step 3: Upload Documents to PDF.co
Node: PDF.co API → Upload File
Settings:
- Binary File:
True
- Input Binary Field:
file
- File Name:
={{ $json.filename }}
Success Looks Like: All PDF attachments are uploaded to PDF.co and return URLs for further processing.
Step 4: Categorize Documents
Node: Switch → Rules
Settings: Configure advanced routing rules:
- Route 1 (Invoice w/ Receipt):
{{ $json.filename }}
contains "Invoice" - Route 2 (Project Summary):
{{ $json.filename }}
contains "Project" - Route 3 (Delivery Confirmation):
{{ $json.filename }}
contains "Delivery"
Success Looks Like: Documents are automatically categorized for appropriate handling in the next steps.
Step 5: Split Document
Node: PDF.co API → Split PDF
Settings:
- Preparation: Link Switch output 0 to Split PDF
- URL:
={{ $json.url }}
- Split By:
Page Numbers
- Pages:
1-2, 3-5, 6-7
(customize based on your document structure)
Success Looks Like: The invoice is split into three separate documents, each with its corresponding URL.
Step 6: Gather All Documents
Node: Merge → Append
Settings:
- Number of Inputs:
3
(adjust based on your routing) - Connect the outputs from:
- Split PDF node
- Switch output 1
- Switch output 2
Success Looks Like: All relevant document URLs are combined into a single list for final merging.
Step 7: Prepare Document Sequence for Merging
Node: Code (JavaScript)
Settings: Use the provided JavaScript code to define the merge order. Download JavaScript Code here.
Success Looks Like: Documents are arranged in the correct sequence: Invoice → Project Summary → Terms & Conditions → Delivery Confirmation → Payment Receipt
Step 8: Combine All Documents
Node: PDF.co API → Merge PDF
Settings:
- Input Links: Map the ordered URLs array
={{ $json.urls[0] }}
={{ $json.urls[1] }}
={{ $json.urls[2] }}
={{ $json.urls[3] }}
={{ $json.urls[4] }}
Success Looks Like: All documents are combined into a single, professionally organized PDF package ready for delivery or archival.
Note: Visit our API Docs to learn more about the PDF Merge endpoint.
Step 9: Apply Completion Stamp
Node: PDF.co API → Add Text/Images to PDF
Settings:
- URL:
={{ $json.url }}
- Tip: Use the PDF Inspector tool to easily find and fine-tune the placement of text and images on your certificate.
- Import this sample project in the tool to explore how it works.
- Text Annotations:
- Text:
PROJECT CLOSED | Delivered ☑ Accepted ☑ Paid ☑ | {{ $now.format('DD')}}
- X:
3.31
- Y:
822.11
- Font Size:
10
- Color:
#0E9923
- Font Name:
Segoe UI Symbol
- Pages:
0-
- Width:
585.04
- Height:
17.61
- Alignment:
Center
- Text:
Success Looks Like: A completion stamp is applied to the bottom of each page in the final document.
Note: Visit our API Docs to learn more about the PDF Add endpoint.
Step 10: Save Completed Package to Google Drive
- Node: Google Drive → Upload
- Settings:
- Input Data Field Name:
data
- Parent Drive From LIst:
My Drive
- Parent Folder From LIst:
Completed Invoice
- Input Data Field Name:
Success Looks Like: The final PDF appears in your designated Google Drive folder.
Congrats! You’ve built a complete document assembly system that intelligently organizes, splits, merges, and finalizes documents—ready for delivery or storage.
Built something cool? Share it with us @pdfdotco
Related Tutorials



