Back to PDF Merger

    How to Use PDF Merger

    Three ways to merge PDFs — the interactive browser app, the REST API, or the MCP tool for AI agents.

    Browser App

    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

      1

      Add your PDFs

      Drag files onto the left panel or click anywhere in it to open a file picker. Add as many PDFs as you like — each appears as a collapsible card.
      2

      Select pages

      Expand a card to see thumbnails. Click to toggle individual pages, or type a selection string like 1-3,7,10-12. Use a reverse range like 10-6 to reverse order.
      3

      Send to output

      Press the → Output button on a file card to push your selection into the right-hand output panel.
      4

      Arrange & preview

      Drag output pages into order. Use Insert Rules in the output header to interleave pages from multiple sources automatically.
      5

      Merge & download

      Click Merge. The PDF is built locally and downloaded immediately.

    Page selection syntax

    * or emptyAll pages
    3Page 3 only
    2-5Pages 2, 3, 4, 5
    10-6Pages 10, 9, 8, 7, 6 (reverse)
    1-3, 8, 11-13Multiple segments, comma-separated
    REST API

    Server-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

    SimpleAll pages appended in array order
    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.pdf
    InterleaveA1 B1 A2 B2 … — also: zip, cross, alternate
    curl -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.pdf
    RulePrecise control over page order
    curl -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

    moderuleresult
    omittedemptysimple
    omittedpresentrule
    simple or interleavepresent400 — remove rule or set mode to "rule"
    ruleempty400 — rule string required
    MCP Tool

    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 nameMergePDF — appears in tools/list after connecting
    • AuthBearer token in Authorization header (JWT or OAuth APIAccessToken)
    • Binary responseMerged PDF returned as base64 inside the MCP content block
    • Full parityAll 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

    1. 1Call UploadFile for each PDF — collect the UUID filenames returned.
    2. 2Call MergePDF with the UUIDs, selection strings, and the desired mode or rule.
    3. 3Decode data_base64 from the response and save or forward the merged PDF.

    Ready to merge?

    No signup, nothing uploaded, instant download.

    Open PDF Merger