Tools
PDF tools
These endpoints work on PDFs that already exist, whether DevilPDF made them or not.
| Endpoint | What it does |
|---|---|
POST /v1/pdf/merge | Join several PDFs into one. |
POST /v1/pdf/split | Cut one PDF into several. |
POST /v1/pdf/protect | Add a password and permissions. |
POST /v1/pdf/fill | Fill form fields. |
POST /v1/pdf/fields | List a PDF's form fields. Free. |
#File inputs
Wherever an endpoint takes a file, you can pass any of these as a string:
| Input | Example |
|---|---|
| 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.
| Field | Default | Description |
|---|---|---|
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. |
filename | per tool | File 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" }
}'| Field | Type | Description |
|---|---|---|
files | array | 2 to 50 file inputs. Pages are joined in this order. |
metadata | object | PDF 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-"] }'| Field | Type | Description |
|---|---|---|
file | string | The PDF to split. |
ranges | array | One output file per range. See below. |
every | number | Instead of ranges: one file per this many pages. Default 1, a file per page. |
password | string | The password, if the PDF is protected. |
Page ranges are one-based and inclusive.
| Range | Pages |
|---|---|
"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.
{
"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 } } }| Field | Type | Meaning |
|---|---|---|
text | string | Up to 60 characters. Latin letters, digits and punctuation. |
opacity | number | 0.02 to 1. Defaults to 0.12. |
angle | number | Degrees, counter-clockwise, -90 to 90. Defaults to 45. |
color | string | Hex 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 }
}'| Field | Type | Description |
|---|---|---|
file | string | The PDF to protect. |
password | string | Needed to open the file. |
owner_password | string | Needed to change permissions. Defaults to password. |
permissions | object | printing, copying, annotating, filling_forms (allowed unless set to false) and modifying (blocked unless set to true). |
current_password | string | The 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
| Message | Cause |
|---|---|
| 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.