Overview
Merging uses the pdf-lib library. A new, empty document is created, and for each input in order every page is copied into it, bringing the page's content and the fonts and images it uses. Only pages are copied: document-level bookmarks and the source files' metadata are not carried into the result.
Input arrives one of two ways. A multipart request is read file by file in form order, and each part must contain a `%PDF-` header in its first kilobyte. Otherwise `urls` is read as a JSON array or a comma-separated string of http(s) links, downloaded one after another with a 10 MB limit each and a 20-second timeout; links must point to public hosts. Fewer than 2 or more than 10 PDFs returns 400. A file over 10 MB, a combined size over 25 MB, or a merge that would pass 500 pages returns 413. A password-protected file returns 400 naming that file, and nothing is merged.
`fileCount` is the number of inputs, `pageCount` the pages in the result, and `size` the byte length of the merged file. `pdfName` is a random file name, `downloadURL` a signed link to the stored copy, and `expires` the moment the link stops working, as Unix time in milliseconds, two days after the call. The PDF is not in the response body, so download it before then.
`sources` lists each input with its 1-based `index`, `name`, `pageCount`, and the `startPage` and `endPage` it occupies in the merged file. For URL inputs, `name` is the last segment of the URL path. On the Free plan `sources` is null.
Endpoint
One host, one path per API. The block below shows this call in four languages; every one of them is the same HTTP request. Making requests covers the timeouts, retries and parameter rules that apply to all of them. The SDKs wrap the same call in a typed client.
curl -X POST https://api.apiverve.com/v1/pdfmerge \
-H "x-api-key: your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"urls": [
"https://raw.githubusercontent.com/mozilla/pdf.js/master/test/pdfs/rotation.pdf",
"https://raw.githubusercontent.com/mozilla/pdf.js/master/test/pdfs/sizes.pdf"
]
}'const res = await fetch('https://api.apiverve.com/v1/pdfmerge', {
method: 'POST',
headers: {
'x-api-key': 'your_api_key_here',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"urls": [
"https://raw.githubusercontent.com/mozilla/pdf.js/master/test/pdfs/rotation.pdf",
"https://raw.githubusercontent.com/mozilla/pdf.js/master/test/pdfs/sizes.pdf"
]
}),
});
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
const { data } = await res.json();
console.log(data);import requests
res = requests.post(
"https://api.apiverve.com/v1/pdfmerge",
headers={"x-api-key": "your_api_key_here"},
json={
"urls": [
"https://raw.githubusercontent.com/mozilla/pdf.js/master/test/pdfs/rotation.pdf",
"https://raw.githubusercontent.com/mozilla/pdf.js/master/test/pdfs/sizes.pdf"
]
},
timeout=15,
)
res.raise_for_status()
print(res.json()["data"])package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
body := strings.NewReader(`{
"urls": [
"https://raw.githubusercontent.com/mozilla/pdf.js/master/test/pdfs/rotation.pdf",
"https://raw.githubusercontent.com/mozilla/pdf.js/master/test/pdfs/sizes.pdf"
]
}`)
req, _ := http.NewRequest("POST", "https://api.apiverve.com/v1/pdfmerge", body)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("x-api-key", "your_api_key_here")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
out, _ := io.ReadAll(res.Body)
fmt.Println(string(out))
}Replace your_api_key_here with the key from your dashboard. When the inputs arrive as a list rather than one at a time, batch requests run up to 200 of them through this same API in a single call.
Authentication
Send your key in the x-api-key header. That is the only auth step — there is no token exchange and no per-endpoint scope to configure. Authentication covers creating, rotating and revoking keys.
A 401 means the key is missing, invalid or expired. A 403 means the key is valid but not permitted here — blocked by a key restriction or an IP allow-list. Running out of credits is a 429.
Parameters
Sent as JSON in the request body. Premium parameters are accepted on every plan but only take effect on plans that include them.
| Parameter | Type | Description |
|---|---|---|
urlsOptional | array | A JSON array of 2 to 10 public PDF URLs, merged in order; a comma- or newline-separated list also works. Or upload the PDFs as multipart files instead |
Response
Every API returns the same three top-level keys, so one response handler covers your whole integration: status, error and data. Only data changes shape. Response format covers the envelope, the other output formats and how premium fields are withheld.
{
"status": "ok",
"error": null,
"data": {
"pdfName": "a356acc9-c44f-4363-9cda-14ed160d5f5d.pdf",
"fileCount": 2,
"pageCount": 5,
"size": 13539,
"expires": 1792230036453,
"downloadURL": "https://storage.googleapis.com/apiverve/APIData/pdfmerge/a356acc9-c44f-4363-9cda-14ed160d5f5d.pdf?GoogleAccessId=635500398038-compute%40developer.gserviceaccount.com&Expires=1792230036&Signature=R5%2B…",
"sources": [
{
"index": 1,
"name": "rotation.pdf",
"pageCount": 2,
"startPage": 1,
"endPage": 2
},
{
"index": 2,
"name": "sizes.pdf",
"pageCount": 3,
"startPage": 3,
"endPage": 5
}
]
}
}
Response fields
Paths are relative to data. Premium fields are absent rather than zeroed on plans that do not include them, so check for presence instead of comparing to 0.
| Field | Type | Example | Description |
|---|---|---|---|
pdfName | string | "a356acc9-c44f-4363-9cda-14ed160d5f5d.pdf" | File name of the merged PDF |
fileCount | number | 2 | Number of PDFs merged |
pageCount | number | 5 | Pages in the merged PDF |
size | number | 13539 | Size of the merged PDF in bytes |
expires | number | 1792230036453 | When the download link expires (Unix time in milliseconds) |
downloadURL | string | "https://storage.googleapis.com/apiverve/APIData/pdfmerge/a356acc9-c44f-4363-9cda-14ed160d5f5d.pdf?Go…" | Signed link to download the merged PDF, valid for 2 days |
sourcesPremium | array[2] | Each input file and the pages it occupies in the merged PDF | |
indexPremium | number | 1 | Position of the file in the request, from 1 |
namePremium | string | "rotation.pdf" | File name of the input |
pageCountPremium | number | 2 | Pages in this input |
startPagePremium | number | 1 | First page of this input in the merged PDF |
endPagePremium | number | 2 | Last page of this input in the merged PDF |
Errors
Read the HTTP status first, then error for the specific reason. The body names the parameter that has to change. Error handling covers the full status list and which of them are worth retrying.
| Status | Meaning | What to do |
|---|---|---|
400 | Input was rejected | Read error; it names the parameter. |
401 | Key missing or invalid | Check the header name and the key value. |
403 | Key valid, but not permitted | A key restriction or IP allow-list; see key scoping. |
429 | Rate limited, or out of credits | Read error to tell them apart; see rate limits. |
Use cases
- Document Packets
- Bundle a contract, its schedules and supporting documents into one PDF for signing or archiving.
- Report Assembly
- Join generated report sections, cover pages and appendices into a single deliverable.
- Invoice Batches
- Combine a customer's invoices or statements for the month into one file to send.
- Application Uploads
- Merge the separate scans a user uploads into one document before storing it.
Other ways to use PDF Merge
Set up PDF Merge on APIVerve, or reach the same source a different way. Your APIVerve account and credits work on all of them — one key, one balance.
Related
More in Documents: