How to Use PDF Merger
Three ways to merge PDFs — the interactive browser app, the REST API, or the MCP tool for AI agents.
Interactive PDF Merger
Runs entirely in your browser. No files are ever uploaded to a server — everything happens locally using PDF.js and pdf-lib.
Drag & drop or browse
Load multiple PDFs at once. Files stay on your device — nothing leaves your browser.
Page selection
Click thumbnails or type a range like 2-5, 8, 11-13 to pick exactly which pages you need.
Drag to reorder
Rearrange output pages by dragging them into any order before merging.
Interleave / Insert Rules
Alternate pages from two documents (A1, B1, A2, B2…) or set a custom insertion step.
Full-resolution preview
Click any output page to see it at full resolution before downloading.
One-click download
The merged PDF is assembled locally and saved directly to your device — no waiting.
Step by step
Add your PDFs
Select pages
1-3,7,10-12. Use a reverse range like 10-6 to reverse order.Send to output
Arrange & preview
Merge & download
Page selection syntax
* or emptyAll pages3Page 3 only2-5Pages 2, 3, 4, 510-6Pages 10, 9, 8, 7, 6 (reverse)1-3, 8, 11-13Multiple segments, comma-separatedServer-side Merge API
Upload files first to get UUIDs, then POST a JSON payload describing how to merge them. The response is the merged PDF ready to save or forward.
Step 1
Upload files
POST each PDF to /api/upload — get a UUID filename back for each.
Step 2
Merge
POST to /api/apps/merger with the file UUIDs and your merge options.
Step 1 — Upload a PDF
curl -X POST https://api.docmiral.com/api/upload \
-H "Authorization: Bearer YOUR_TOKEN" \
-F "file=@contract.pdf"
# Response:
{
"status": 1,
"data": {
"name": "eee466bd-6813-4aaf-9e48-bc5e2b19d7d3.pdf",
"size": 204800,
"extension": ".pdf"
}
}Repeat for each file. Use the returned name as the file ID in the merger.
Step 2 — Merge
curl -X POST https://api.docmiral.com/api/apps/merger \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"files": [
{
"name": "first",
"file": "eee466bd-6813-4aaf-9e48-bc5e2b19d7d3.pdf",
"selection": "*"
},
{
"name": "second",
"file": "a1b2c3d4-1234-5678-abcd-ef1234567890.pdf",
"selection": "*"
}
]
}' --output merged.pdfcurl -X POST https://api.docmiral.com/api/apps/merger \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"files": [
{
"name": "doc-a",
"file": "eee466bd-6813-4aaf-9e48-bc5e2b19d7d3.pdf",
"selection": "1-5"
},
{
"name": "doc-b",
"file": "a1b2c3d4-1234-5678-abcd-ef1234567890.pdf",
"selection": "1-5"
}
],
"mode": "interleave"
}' --output merged.pdfcurl -X POST https://api.docmiral.com/api/apps/merger \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"files": [
{
"name": "file-a",
"file": "eee466bd-6813-4aaf-9e48-bc5e2b19d7d3.pdf",
"selection": "2-3,7-10"
},
{
"name": "file-b",
"file": "a1b2c3d4-1234-5678-abcd-ef1234567890.pdf",
"selection": "1-5"
}
],
"mode": "rule",
"rule": "{file-a}-1-4,{file-b}-2-5"
}' --output merged.pdf{file-a}-1-4 picks pages 1–4 of file-a's post-selection pages. Page numbers in rules are 1-based into the selected pages, not the original file.
Mode resolution
| mode | rule | result |
|---|---|---|
| omitted | empty | simple |
| omitted | present | rule |
| simple or interleave | present | 400 — remove rule or set mode to "rule" |
| rule | empty | 400 — rule string required |
MCP — AI Agent Integration
The Docmiral MCP server exposes PDF merger as a tool AI agents can call directly. Agents upload files, merge with any selection or rule, and receive the result — all in one conversation turn.
- Tool name — MergePDF — appears in tools/list after connecting
- Auth — Bearer token in Authorization header (JWT or OAuth APIAccessToken)
- Binary response — Merged PDF returned as base64 inside the MCP content block
- Full parity — All modes (simple, interleave, rule) work identically to the REST API
Connect (Claude Desktop)
// claude_desktop_config.json
{
"mcpServers": {
"docmiral": {
"url": "https://api.docmiral.com/api/mcp",
"headers": {
"Authorization": "Bearer YOUR_TOKEN"
}
}
}
}Initialize
POST https://api.docmiral.com/api/mcp
Authorization: Bearer YOUR_TOKEN
{ "jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {} }Call MergePDF
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "MergePDF",
"arguments": {
"body": {
"files": [
{
"name": "file-a",
"file": "eee466bd-6813-4aaf-9e48-bc5e2b19d7d3.pdf",
"selection": "2-3,7-10"
},
{
"name": "file-b",
"file": "a1b2c3d4-1234-5678-abcd-ef1234567890.pdf",
"selection": "1-5"
}
],
"mode": "rule",
"rule": "{file-a}-1-4,{file-b}-2-5"
}
}
}
}Response
{
"jsonrpc": "2.0",
"id": 3,
"result": {
"content": [{
"type": "text",
"text": "{
"type": "binary",
"content_type": "application/pdf",
"filename": "merged.pdf",
"data_base64": "JVBERi0xLjQK...",
"size": 42318
}"
}]
}
}Decode data_base64 to get the raw PDF bytes. File UUIDs must come from a prior UploadFile tool call.
Typical agent workflow
- 1Call UploadFile for each PDF — collect the UUID filenames returned.
- 2Call MergePDF with the UUIDs, selection strings, and the desired mode or rule.
- 3Decode data_base64 from the response and save or forward the merged PDF.
Ready to merge?
No signup, nothing uploaded, instant download.