DEV Community

Adam Bari
Adam Bari

Posted on

Merge, split, and watermark PDFs from your app with one API (no native libraries)

If you've ever had to merge a few PDFs, stamp a "CONFIDENTIAL" watermark, or turn a stack of images
into a single PDF on the server, you know the pain: pdf-lib, pdftk, ghostscript, native
binaries that won't install on your host, and an afternoon gone.

Here's a lighter option: a small HTTP API that does the common PDF jobs for you. You POST a file, you get
a PDF back. No dependencies, no native build steps, works from any language.

I'll show merge, watermark, and images-to-PDF with copy-paste examples in cURL and Node.

The endpoints

The PDF Toolkit API exposes six routes:

Endpoint Does
POST /v1/pdf/merge Combine multiple PDFs into one
POST /v1/pdf/split Split a PDF into pages / ranges
POST /v1/pdf/rotate Rotate pages
POST /v1/pdf/watermark Stamp text over every page
POST /v1/pdf/info Page count, size, metadata
POST /v1/images-to-pdf Turn JP/PNG images into a PDF

It's on RapidAPI, so you get a key and a free tier (100 requests/day) to try it. Grab a key by
subscribing to the free BASIC plan, then copy your X-RapidAPI-Key from the dashboard.

1. Merge PDFs (cURL)

curl -X POST \
  'https://pdf-toolkit-api2.p.rapidapi.com/v1/pdf/merge' \
  -H 'X-RapidAPI-Key: YOUR_KEY' \
  -H 'X-RapidAPI-Host: pdf-toolkit-api2.p.rapidapi.com' \
  -F 'files=@invoice.pdf' \
  -F 'files=@terms.pdf' \
  --output merged.pdf
Enter fullscreen mode Exit fullscreen mode

That's it — merged.pdf is written to disk. Two -F files=@... fields become one document, in order.

2. Merge PDFs (Node.js)

import fs from "node:fs";
import FormData from "form-data";
import axios from "axios";

const form = new FormData();
form.append("files", fs.createReadStream("invoice.pdf"));
form.append("files", fs.createReadStream("terms.pdf"));

const res = await axios.post(
  "https://pdf-toolkit-api2.p.rapidapi.com/v1/pdf/merge",
  form,
  {
    responseType: "arraybuffer",
    headers: {
      ...form.getHeaders(),
      "X-RapidAPI-Key": process.env.RAPIDAPI_KEY,
      "X-RapidAPI-Host": "pdf-toolkit-api2.p.rapidapi.com",
    },
  }
);

fs.writeFileSync("merged.pdf", res.data);
console.log("Wrote merged.pdf");
Enter fullscreen mode Exit fullscreen mode

3. Watermark every page

Great for draft stamps, "PAID", or a customer name across an exported report:

curl -X POST \
  'https://pdf-toolkit-api2.p.rapidapi.com/v1/pdf/watermark' \
  -H 'X-RapidAPI-Key: YOUR_KEY' \
  -H 'X-RapidAPI-Host: pdf-toolkit-api2.p.rapidapi.com' \
  -F 'file=@report.pdf' \
  -F 'text=CONFIDENTIAL' \
  --output stamped.pdf
Enter fullscreen mode Exit fullscreen mode

4. Turn images into a PDF

Scanned receipts, screenshots, a photo set — one PDF:

curl -X POST \
  'https://pdf-toolkit-api2.p.rapidapi.com/v1/images-to-pdf' \
  -H 'X-RapidAPI-Key: YOUR_KEY' \
  -H 'X-RapidAPI-Host: pdf-toolkit-api2.p.rapidapi.com' \
  -F 'files=@page1.jpg' \
  -F 'files=@page2.png' \
  --output out.pdf
Enter fullscreen mode Exit fullscreen mode

When an API beats a library

To be fair — if you're already comfortable with pdf-lib and you only do one PDF task, a library is
fine and free. An API earns its keep when:

  • You're on a host where native PDF binaries are a nightmare (serverless, edge, locked-down PaaS).
  • You want one integration for merge + split + rotate + watermark + images, not five libraries.
  • You'd rather not maintain PDF code at all.

At 100 requests/day free and a few dollars a month for real volume, it's usually cheaper than the hour
you'd spend fighting ghostscript.

Try it

Free tier, no credit card to start: PDF Toolkit API on RapidAPI.
If you need image resizing/converting/compression too, there's a companion
Image Toolkit API with the same shape.

Built it because I kept re-writing the same PDF glue code. If you hit a rough edge or want an endpoint
that isn't there, drop a comment — I read them.

Top comments (0)