Docs / PDF tools

Tools

PDF tools

These endpoints work on PDFs that already exist, whether DevilPDF made them or not.

EndpointWhat it does
POST /v1/pdf/mergeJoin several PDFs into one.
POST /v1/pdf/splitCut one PDF into several.
POST /v1/pdf/protectAdd a password and permissions.
POST /v1/pdf/fillFill form fields.
POST /v1/pdf/fieldsList a PDF's form fields. Free.

#File inputs

Wherever an endpoint takes a file, you can pass any of these as a string:

InputExample
A document id"doc_nWWGc4ehhC44vpOsHFGn". The document must still have a stored file.
An https URL"https://example.com/files/cover.pdf". Must be public.
Base64 content"JVBERi0xLjcK...". A data: URI works too.

Input files can be up to 30 MB each.

#Output

Every tool takes the same output fields as a render.

FieldDefaultDescription
output"url"url returns a document with a download link. base64 adds the file to the JSON. file returns the raw PDF and stores nothing.
filenameper toolFile name without extension.

Each file a tool produces counts as one document. A merge is one document; a split into five parts is five.

#Merge

curl https://devilpdf.com/v1/pdf/merge \
  -H "Authorization: Bearer $DEVILPDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "files": [
      "doc_nWWGc4ehhC44vpOsHFGn",
      "https://example.com/files/terms.pdf"
    ],
    "filename": "invoice-with-terms",
    "metadata": { "title": "Invoice INV-1001 and terms" }
  }'
FieldTypeDescription
filesarray2 to 50 file inputs. Pages are joined in this order.
metadataobjectPDF properties for the result: title, author, subject, keywords, creator.

Returns one document. A common use: render an invoice, then merge it with a static terms sheet.

#Split

curl https://devilpdf.com/v1/pdf/split \
  -H "Authorization: Bearer $DEVILPDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "file": "doc_nWWGc4ehhC44vpOsHFGn", "ranges": ["1-3", "4-"] }'
FieldTypeDescription
filestringThe PDF to split.
rangesarrayOne output file per range. See below.
everynumberInstead of ranges: one file per this many pages. Default 1, a file per page.
passwordstringThe password, if the PDF is protected.

Page ranges are one-based and inclusive.

RangePages
"3"Page 3.
"1-3"Pages 1 to 3.
"4-"Page 4 to the end.
"-2"The first two pages.

Ranges may overlap, and a range that runs past the last page stops at the last page. A range that starts after it is an error.

The response is a list of documents, in the order of your ranges. A split can produce at most 200 files, and "output": "file" is not available because there is more than one.

Response
{
  "object": "list",
  "data": [
    { "object": "document", "id": "doc_A1...", "filename": "split-1-3.pdf", "pages": 3, "url": "https://devilpdf.com/f/..." },
    { "object": "document", "id": "doc_B2...", "filename": "split-4-.pdf", "pages": 2, "url": "https://devilpdf.com/f/..." }
  ],
  "split": true
}

#Watermark

Stamp text across every page of a document as you render it. Add pdf.watermark to any render request:

curl https://devilpdf.com/v1/render \
  -H "Authorization: Bearer $DEVILPDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "template": "invoice",
    "data": { "number": "INV-1001" },
    "pdf": { "watermark": "DRAFT" }
  }'

Pass an object to control how it looks:

{ "pdf": { "watermark": { "text": "PAID", "color": "#16a34a", "opacity": 0.2, "angle": 30 } } }
FieldTypeMeaning
textstringUp to 60 characters. Latin letters, digits and punctuation.
opacitynumber0.02 to 1. Defaults to 0.12.
anglenumberDegrees, counter-clockwise, -90 to 90. Defaults to 45.
colorstringHex colour. Defaults to grey.

The text is sized to fit the page, so it works on any paper size and orientation. Watermarks are included on every plan.

#Protect

curl https://devilpdf.com/v1/pdf/protect \
  -H "Authorization: Bearer $DEVILPDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "file": "doc_nWWGc4ehhC44vpOsHFGn",
    "password": "open-sesame",
    "permissions": { "copying": false }
  }'
FieldTypeDescription
filestringThe PDF to protect.
passwordstringNeeded to open the file.
owner_passwordstringNeeded to change permissions. Defaults to password.
permissionsobjectprinting, copying, annotating, filling_forms (allowed unless set to false) and modifying (blocked unless set to true).
current_passwordstringThe existing password, if the file is already protected.

Pass password, owner_password, or both. With only owner_password, anyone can open the file but the permissions are enforced. Files are encrypted with AES-256.

To protect a document as you create it, use pdf.password on the render instead and skip this step.

#Fill

Fills the form fields of a PDF. Covered in detail in forms and signatures.

curl https://devilpdf.com/v1/pdf/fill \
  -H "Authorization: Bearer $DEVILPDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "file": "https://example.com/forms/application.pdf",
    "fields": { "full_name": "Dana Whitfield", "agree": true },
    "flatten": true
  }'

#Errors

MessageCause
That file is not a PDF we can read.The input is not a PDF, or is damaged.
That PDF is password protected.Pass its password as password (or current_password for protect).
Document "doc_..." has no stored file.The document's file has expired, or it was created with "output": "file".
Could not download "file".The URL did not return the file. It must be public and use https.

All of these have the type invalid_request. A tool call that fails is not counted.