
Email-to-Booklet: Parse, Personalize, and Merge Legal PDFs with n8n + PDF.co
6 MIN READ
By the end of this tutorial, you’ll have a fully automated workflow that:
This saves hours of manual splitting and ensures that large PDFs are neatly organized into smaller files in Drive.
Before you begin, you’ll need:
n8n-nodes-pdfco) installed in the same n8n instance where the workflow will be importedOption A: I Want It Working Now
Option B – Learn by Building: Follow the step-by-step tutorial below.
Upload to Google Drive → Saves each file individually in your chosen folder
Watch your inbox for new emails with the subject “Multiple Invoices”. When found, it automatically downloads the attached PDF so the workflow can process it.
Node: Email Trigger (IMAP)
["UNSEEN", ["SUBJECT", "Multiple Invoices "]]Success: Workflow triggers only when a new Multiple Invoices email with attachments is received.
Sends the attached PDF file securely to PDF.co. This makes the file available for further processing, like checking page count or splitting.
Node: PDF.co API → Upload File
attachment_0={{ $json.subject }}Success: Email attachment is uploaded, and PDF.co returns a file URL.
Uses PDF.co to analyze the uploaded file. It retrieves the total number of pages (PageCount), which is needed to decide if splitting is required.
Node: PDF.co API → PDF Information & Form Fields
={{ $json.url }}Success: PDF.co responds with metadata, including PageCount.
A custom JavaScript block checks how many pages the PDF has:
This ensures only big PDFs get split.
Node: Code
Here’s the logic you used:
// Get PageCount safely
const pageCount = parseInt($json.body.PageCount, 10);
if (isNaN(pageCount) || pageCount <= 0) {
throw new Error("Invalid or missing PageCount value.");
}
const ranges = [];
// Rule 1: If below 10 pages → keep whole file
if (pageCount < 10) {
ranges.push(`1-${pageCount}`);
}
// Rule 2: If 15 pages or more → split into 10-page batches
else if (pageCount >= 15) {
const batchSize = 10;
for (let start = 1; start <= pageCount; start += batchSize) {
const end = Math.min(start + batchSize - 1, pageCount);
ranges.push(`${start}-${end}`);
}
}
// Rule 3: If between 10 and 14 → keep whole file
else {
ranges.push(`1-${pageCount}`);
}
return [{
pages: ranges.join(",")
}];Success: Produces page ranges like 1-10,11-20,21-30.
Calls PDF.co again with the page ranges from Step 4. PDF.co creates separate files for each range (e.g., 1-10.pdf, 11-20.pdf).
Node: PDF.co API → Split PDF
={{ $('Assign URLs to Binary Files').item.json.url }}={{ $json.pages }}Success: Returns an array of split file URLs.
The split step returns all file URLs in one array. This code breaks them into individual items, so each file can be processed one by one.
Node: Code
// Get the array of URLs from the Split PDF output
const urls = $json.body;
if (!Array.isArray(urls)) {
throw new Error("Expected 'body' to be an array of URLs, got: " + typeof urls);
}
return urls.map(url => ({
json: { url }
}));Success: Each split file URL is turned into an individual n8n item.
For each file URL, the HTTP Request node downloads the PDF. This prepares the binary data so it can be uploaded to Google Drive.
Node: HTTP Request
={{ $json.url }}Success: Downloads each split file individually.
Finally, each file is uploaded individually into your Google Drive folder (not zipped). Each file is named according to the original split part (like Multiple_Invoices_page1-10.pdf).
Node: Google Drive → Upload
dataFile Name: {{$json["url"].split("/").pop().split("?")[0]}}
Success: Each split file is uploaded to Drive as a standalone PDF.
You’ve now automated a workflow that:
No more manual splitting — just drop invoices into your inbox, and everything else happens automatically.

6 MIN READ

6 MIN READ

6 MIN READ

6 MIN READ
Create an account, get an API key and test a request.