Merging multiple Base64 strings to one PDF / Merging PDFs

Describe the issue/error/question

I currently have a workflow where I generate multiple PDF files (as many as items are there). From the API Call I am doing, I am getting a Base64 string back. For each item (let’s say 4 items) in the inital API call, I recieve a Base64 string back.

I have already used a custom JS function to turn these strings into individual PDFs.

However, as a last step, I would like to send these PDFs bundled back (i.e. via Email).

Please share the workflow

(Select the nodes and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow respectively)

Share the output returned by the last node

{
“meta”: {
“instanceId”: “a6a668a234ac488cb2f2c97a39c802c17330080f278b03dfcedf4bf30b292c88”
},
“nodes”: [
{
“parameters”: {
“functionCode”: “// First we build our binary data object\nconst binaryData = {\n data: {\n data: $json.orderResult.parcellabelsPDF, // item.body.pdf_data is the path to your base64 string\n fileName: $node["FilterConfirmed1"].json.order_id + ".pdf", // I am using a hard coded file name here…\n mimeType: ‘application/pdf’, // and a hard coded mime type because I couldn’t see if these come through on your scree nshot\n }\n}\n\n// Now we set the binary data on the item\nsetBinaryData(binaryData);\n\n// And finally we return everything\nreturn item;”
},
“id”: “f112b646-4cd2-465e-840a-f0e28490068e”,
“name”: “CreateBinaryData”,
“type”: “n8n-nodes-base.functionItem”,
“typeVersion”: 1,
“position”: [
1880,
380
]
}
],
“connections”: {}
}

Information on your n8n setup

  • n8n version: 0.199.0
  • Database you’re using (default: SQLite): SQLite
  • Running n8n with the execution process [own(default), main]: own
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: Docker

Hi @lmo272, I am afraid my understanding of the PDF standard isn’t deep enough to suggest a way of combining multiple separate PDF files into a single PDF.

Would perhaps sending out these four separate files in a single email (with four attachments) or compressed in a ZIP archive be an option for you?

Hi @MutedJam,

Thanks for your answer.

Unfortunately, sending out separately is not an option.

I solved the overall problem different :). Thanks again!

1 Like

Glad to hear you found a solution, thanks for confirming!

Hello there @ MutedJam, i have same problem
I have 2 base64 and i want to convert it in one base64.

Please can you tell me your solution?

Thanks Blerion

Hi @Blerion_Muco, I am afraid my knowledge of the PDF format has not changed since this topic first came up. Since n8n doesn’t have a built-in operation for merging multiple PDF files into one I suggest you use an external service for this.

I know the folks from Cloud Convert built a community node that supports such an operation, though I haven’t tested it first hand yet. Could be worth a try though, you can find the node here:

To convert base64 data into an actual binary file (and back) you can use the Move Binary Data node as shown here.