Merge Multiple PDF Files
PDF4me Merge is a REST endpoint that combines multiple PDFs into a single document. POST an array of Base64-encoded files to /api/v2/Merge with an output name, and the API appends them in array order and returns the merged PDF as raw bytes. Set async true for large batches and poll the Location URL until the result is ready.
Takes two or more PDFs and returns one: invoice plus attachments, cover page plus report, a folder of scans consolidated into a single file. The array order is the page order, so your code fully controls the result. This is the plain concatenation endpoint; overlaying pages on top of each other is a separate action (Merge Overlay).
Authenticating Your API Request
Every PDF4me REST call must include your API key in the Authorization header as Basic auth. Get or rotate your key from the developer dashboard.
Endpoint
/api/v2/Mergehttps://api.pdf4me.com/api/v2/MergeImportant Facts You Should Not Miss
docContent is a single string, here it is an ARRAY of Base64 strings. The array order is the merge order; there is no separate ordering parameter."async": true the API answers 202 Accepted with a Location header. Poll it with GET about every 10 seconds (the official samples use 10s intervals, up to 20 retries) until 200 returns the merged file.HTTP setup
Method: POST
URL: https://api.pdf4me.com/api/v2/Merge
Content-Type: application/json
Authorization: Basic <your PDF4me API key>
A 200 response body is the merged PDF as raw bytes: save it directly. A 202 response means the merge is running asynchronously: poll the Location URL until 200.
How do sync and async processing differ?
The async flag changes the response contract, not the merge result. Pick by batch size.
| Sync vs async | "async": false (default) | "async": true |
|---|---|---|
| Response on success | 200 with the merged PDF as raw bytes | 202 Accepted with a Location polling URL |
| Connection | Held open until the merge finishes | Returns immediately |
| How to get the file | Save the response body directly | GET the Location URL every ~10 seconds until it answers 200 with the bytes |
| Best for | A few small files | Large batches and big documents |
API body fields
| Parameter | Required | Type | What it does | Example |
|---|---|---|---|---|
docContent | Required | array of strings | An array of Base64-encoded PDF files, at least two entries. The array order is the merge order of the output document. | ["JVBERi0x...", "JVBERi0x..."] |
docName | Required | string | Output filename for the merged PDF. | merged.pdf |
async | Optional | boolean | false (default) returns the merged PDF directly on 200. true returns 202 plus a Location URL to poll, for large batches. | true |
Sample payloads
Merge two PDFs synchronously
{
"docContent": [
"JVBERi0xLjcKJb...first PDF Base64...",
"JVBERi0xLjcKJb...second PDF Base64..."
],
"docName": "merged.pdf"
}
Merge a large batch asynchronously
{
"docContent": [
"JVBERi0x...cover...",
"JVBERi0x...report...",
"JVBERi0x...appendix-a...",
"JVBERi0x...appendix-b..."
],
"docName": "quarterly-pack.pdf",
"async": true
}
Postman collection tips
curl example
curl -X POST https://api.pdf4me.com/api/v2/Merge \
-H "Content-Type: application/json" \
-H "Authorization: Basic YOUR_API_KEY" \
-d '{
"docContent": [
"'"$(base64 -w 0 first.pdf)"'",
"'"$(base64 -w 0 second.pdf)"'"
],
"docName": "merged.pdf"
}' \
--output merged.pdf
What does the API return?
| Field | Type | What it contains |
|---|---|---|
200 response body | Binary (application/pdf) | The merged PDF file itself as raw bytes. Save it directly to disk; do not JSON-parse or Base64-decode. |
202 Location header | URL | Async mode only: the polling URL. GET it about every 10 seconds until it returns 200 with the merged PDF bytes. |
4xx/5xx response body | JSON or text | Error details: 400 for malformed Base64 or a bad payload shape, 401 for a missing or invalid API key, 500 for server-side processing failures. |
Code samples
Official, runnable samples for this exact endpoint, per language:
FAQ
Why merge PDFs via API instead of a desktop tool?
Desktop and web merge tools are fine for one-off jobs, but they need a human to select files, drag them into order, and download the result. The API does the same concatenation as one deterministic request per batch, with the order fixed by your code rather than by drag-and-drop. The output is a standard PDF conforming to the ISO 32000 specification, so it opens in any reader and feeds cleanly into the next pipeline step, whether that is compression, OCR, or e-signing.