PDF Tools API
The PDF tools run on PDFs you send them: split a PDF, extract or rotate pages,
encrypt or decrypt it, add a watermark or page numbers, compress or flatten it,
render its pages as images, make a PDF from images, or extract its text. Two
more convert a page of HTML or some Markdown to a PDF. Each run is a job
(job_...). A job reads one PDF (up to 100 images for images_to_pdf, or the
HTML or Markdown you send), makes new files, and keeps them until it expires: by your account’s
expiry setting for the PDF tools,
unless the request sets its own.
Send every request to https://sync.api.docspring.com/api/v2 (EU accounts:
https://sync.api-eu.docspring.com/api/v2). Authenticate with an
API token: its ID and secret are the username
and password for HTTP Basic auth.
export DOCSPRING_TOKEN_ID="your_token_id"export DOCSPRING_TOKEN_SECRET="your_token_secret"The tools
Section titled “The tools”Each tool has its own endpoint, POST /api/v2/jobs/<tool>, and returns a job.
| Tool | What it does |
|---|---|
split_pdf | Splits a PDF into a file per page, every few pages, or by ranges |
extract_pages | Makes a PDF of some pages, in any order, to remove or reorder pages |
rotate_pages | Turns some or all pages by 90, 180 or 270 degrees |
encrypt_pdf | Adds a password and limits printing, copying and changes (AES-256) |
decrypt_pdf | Removes the password and permissions from a PDF |
watermark_pdf | Puts text such as CONFIDENTIAL across the pages |
add_page_numbers | Numbers the pages, with your own label such as “Page 2 of 9” |
compress_pdf | Makes a PDF smaller without losing quality |
flatten_pdf | Draws form fields and annotations into the pages |
pdf_to_images | Renders pages as PNG or JPEG images, at the resolution you choose |
images_to_pdf | Makes a PDF with one PNG or JPEG image on each page |
pdf_to_text | Extracts a PDF’s text into a .txt file, in reading order |
html_to_pdf | Converts a page of HTML and CSS to a PDF |
markdown_to_pdf | Converts Markdown to a PDF, with our stylesheet or your CSS |
To merge PDFs into one, use Combine PDFs.
Send a file
Section titled “Send a file”Every tool takes input, the PDF to read, except images_to_pdf, which takes
inputs: a list of 1 to 100 images. Each input has a type:
{ "type": "url", "url": "https://example.com/contract.pdf" }{ "type": "upload", "cache_id": "cache/4f1c2b9e8d7a6f5e.pdf", "filename": "contract.pdf" }{ "type": "custom_file", "id": "cfi_1234567890abcdef01" }{ "type": "submission", "id": "sub_1234567890abcdef01" }{ "type": "combined_pdf", "id": "com_1234567890abcdef01" }{ "type": "job", "id": "job_1234567890abcdef01", "file": 2 }{ "type": "base64", "data": "JVBERi0xLjcK...", "filename": "contract.pdf" }url: DocSpring downloads the file, up to 100 MB (10 MB for a file of HTML or Markdown).upload: a file on your server, up to 100 MB (10 MB for a file of HTML or Markdown). Get an upload URL withGET /uploads/presign, upload the file to it with itsfields, then send thefields.keyascache_id. You can send the samecache_idto several jobs.custom_file: a file you keep in your account (POST /custom_files).submissionandcombined_pdf: the PDF that DocSpring made. It must be processed, and not expired.job: a file another job made, so you can run one tool after another.filepicks which of its files to read, starting at 1 (the default). The other job must have finished.base64: the file itself, up to 7 MB: the request body can be up to 10 MB. Send larger files as uploads.
Each input can have a filename. The job names the files it makes after it:
contract.pdf makes contract-1.pdf, contract-2.pdf and so on from a split.
Without one, the job uses the custom file’s, the URL’s or the job file’s name,
or else its own ID.
Every tool also takes:
metadata: your own data about the job, such as an ID from your app (up to 50 keys).expires_in: seconds after the job finishes until its files are deleted, up to 10 years (315360000). Without it, the account’s expiry setting for the PDF tools decides.
An input that can’t be read, such as an ID that isn’t in your account or a
submission that has no PDF yet, is a 422 error, and no job is created.
Choose pages
Section titled “Choose pages”pages (and each of split_pdf’s ranges) is a list of pages and ranges,
separated by commas: N, N-M, z, N-z or z-N, where z is the last
page. Pages start at 1.
pages | Means |
|---|---|
1-3,5,8-z | Pages 1 to 3, page 5, and page 8 to the end |
2-z | Every page but the first |
z | The last page |
z-1 | Every page, last first |
A page the PDF doesn’t have makes the job fail, and its error_message says
how many pages the PDF has.
The job
Section titled “The job”sync.api.docspring.com waits until the job has run, so the response is the
job with its files:
{ "id": "job_1234567890abcdef01", "operation": "split_pdf", "state": "processed", "inputs": [ { "type": "url", "url": "https://example.com/contract.pdf", "filename": "contract.pdf" } ], "options": { "ranges": ["1-2", "3-z"] }, "files": [ { "download_url": "https://downloads.docspring.com/store/...pdf?Expires=...&Signature=...", "filename": "contract-1.pdf", "content_type": "application/pdf", "size": 48213, "sha256": "9f2c...", "pages": [1, 2] }, { "download_url": "https://downloads.docspring.com/store/...pdf?Expires=...&Signature=...", "filename": "contract-2.pdf", "content_type": "application/pdf", "size": 51874, "sha256": "41ab...", "pages": [3, 4, 5] } ], "credits": 1, "metadata": {}, "error_message": null, "expired": false, "expires_at": "2026-11-02T09:30:04Z", "processed_at": "2026-11-01T09:30:04Z", "created_at": "2026-11-01T09:30:02Z", "updated_at": "2026-11-01T09:30:04Z"}stateispendinguntil the job has run, thenprocessed, orerrorwhen it couldn’t run. Checkstate: a job that failed still returns201, with the reason inerror_message.- Each file’s
download_urlis temporary. Get the job again withGET /jobs/{job_id}for new links.pageslists the input’s pages that the file holds. optionsshows the options you sent. Passwords are never shown.creditsis what the job used, once it has run.
Waiting
Section titled “Waiting”On sync.api.docspring.com, a request waits up to about 95 seconds for its
job. A job that takes longer returns a 504 with a polling_timeout error and
the job_id: the job is still running, so get it by that ID rather than send
the request again. Add ?wait=false to get the pending job straight away,
then get it until its state isn’t pending, or have a
webhook tell you: job.processed when its files
are ready, job.failed when it fails. See
Synchronous requests.
Send an Idempotency-Key header, such as a UUID, with each new job. If a
request times out or the connection drops, send it again with the same key: you
get the first job back instead of a second one.
Split a PDF
Section titled “Split a PDF”split_pdf makes a file of pages_per_file pages each (the default, 1, makes a
file per page), or a file per range in ranges, such as ["1-2", "3-z"]. Send
one of them, not both. A page can be in more than one range. A job makes at most
100 files: for a PDF of more than 100 pages, put more pages in each file.
curl https://sync.api.docspring.com/api/v2/jobs/split_pdf \ -u "$DOCSPRING_TOKEN_ID:$DOCSPRING_TOKEN_SECRET" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: $(uuidgen)" \ -d '{ "input": { "type": "url", "url": "https://example.com/contract.pdf" }, "ranges": ["1-2", "3-z"] }'Extract pages
Section titled “Extract pages”extract_pages makes a PDF of the pages you list, in that order. Pages you
leave out are removed, and a page can be listed twice. 3,1-2 moves page 3 to
the front, and z-1 reverses the PDF.
curl https://sync.api.docspring.com/api/v2/jobs/extract_pages \ -u "$DOCSPRING_TOKEN_ID:$DOCSPRING_TOKEN_SECRET" \ -H "Content-Type: application/json" \ -d '{ "input": { "type": "submission", "id": "sub_1234567890abcdef01" }, "pages": "1-3,5" }'Rotate pages
Section titled “Rotate pages”rotate_pages turns each of pages (default every page) by angle degrees
clockwise: 90, 180, 270, or -90 for anticlockwise. The angle is added
to the page’s current rotation.
curl https://sync.api.docspring.com/api/v2/jobs/rotate_pages \ -u "$DOCSPRING_TOKEN_ID:$DOCSPRING_TOKEN_SECRET" \ -H "Content-Type: application/json" \ -d '{ "input": { "type": "url", "url": "https://example.com/scan.pdf" }, "angle": 90, "pages": "2,4" }'Encrypt a PDF
Section titled “Encrypt a PDF”encrypt_pdf encrypts the PDF with AES-256.
user_password: the password the PDF needs to open. Without it, the PDF opens without one and the permissions still apply.owner_password: the password that lifts the permissions. Without it, DocSpring uses a random one that nobody knows.permissions:print,copy,modify(change the PDF, fill its forms and assemble its pages) andannotate(add comments), eachtrueorfalse. Everything is allowed by default.
Passwords are 1 to 127 characters, with no line breaks. DocSpring never shows
them in the job and deletes them once the job has run, so keep your own copy.
PDF viewers apply the permissions, but a PDF without a user_password can be
opened and decrypted by anyone: use a user_password to keep a PDF private.
curl https://sync.api.docspring.com/api/v2/jobs/encrypt_pdf \ -u "$DOCSPRING_TOKEN_ID:$DOCSPRING_TOKEN_SECRET" \ -H "Content-Type: application/json" \ -d '{ "input": { "type": "submission", "id": "sub_1234567890abcdef01" }, "user_password": "open-sesame", "permissions": { "print": true, "copy": false } }'Decrypt a PDF
Section titled “Decrypt a PDF”decrypt_pdf removes the password and permissions. Send the PDF’s user or
owner password. A PDF that only limits printing or copying opens without one.
The other tools can’t read a PDF that needs a password to open: decrypt it
first, then run the next tool on the decrypted file ({"type": "job", ...}).
curl https://sync.api.docspring.com/api/v2/jobs/decrypt_pdf \ -u "$DOCSPRING_TOKEN_ID:$DOCSPRING_TOKEN_SECRET" \ -H "Content-Type: application/json" \ -d '{ "input": { "type": "custom_file", "id": "cfi_1234567890abcdef01" }, "password": "open-sesame" }'Add a watermark
Section titled “Add a watermark”watermark_pdf puts text across each of pages (default every page).
| Option | Default |
|---|---|
text | Required, up to 200 characters |
font_size | The largest size up to 96 that fits (6–300) |
color | #888888 |
opacity | 0.25 (from 0.05 to 1) |
angle | 45 degrees anticlockwise (-180 to 180) |
layer | over the page content, or under it |
A watermark under the content is hidden where the page is opaque, such as a
scanned page.
curl https://sync.api.docspring.com/api/v2/jobs/watermark_pdf \ -u "$DOCSPRING_TOKEN_ID:$DOCSPRING_TOKEN_SECRET" \ -H "Content-Type: application/json" \ -d '{ "input": { "type": "url", "url": "https://example.com/contract.pdf" }, "text": "CONFIDENTIAL", "color": "#cc0000" }'Add page numbers
Section titled “Add page numbers”add_page_numbers writes text on each of pages (default every page), where
{page} is the page’s number and {total} the last number. The default text
is Page {page} of {total}.
position:bottom_center(the default),bottom_left,bottom_right,top_center,top_leftortop_right.font_size: 6 to 72 points. The default is 10.start_at: the first numbered page’s number. The default is 1.
To skip a cover page and number the rest from 1, send "pages": "2-z".
curl https://sync.api.docspring.com/api/v2/jobs/add_page_numbers \ -u "$DOCSPRING_TOKEN_ID:$DOCSPRING_TOKEN_SECRET" \ -H "Content-Type: application/json" \ -d '{ "input": { "type": "url", "url": "https://example.com/report.pdf" }, "text": "Page {page} of {total}", "position": "bottom_right", "pages": "2-z" }'Watermarks and page numbers use a built-in font with Latin letters, numbers and
punctuation: the Windows-1252 characters. A job whose text has other
characters, such as Greek, Cyrillic, Chinese or emoji, fails with an
error_message that lists them.
Compress a PDF
Section titled “Compress a PDF”compress_pdf makes a PDF smaller without losing quality: it recompresses its
streams and packs its objects, and images keep their quality. A PDF that can’t
be made smaller comes back as it was. It takes no options.
curl https://sync.api.docspring.com/api/v2/jobs/compress_pdf \ -u "$DOCSPRING_TOKEN_ID:$DOCSPRING_TOKEN_SECRET" \ -H "Content-Type: application/json" \ -d '{ "input": { "type": "url", "url": "https://example.com/brochure.pdf" } }'Flatten a PDF
Section titled “Flatten a PDF”flatten_pdf draws the PDF’s form fields and annotations into its pages, so
they can’t be changed. It takes no options.
Some programs fill a form without drawing its values, and leave that to the PDF
reader. flatten_pdf draws those values first, with each field’s own font. When
a value can’t be drawn with its field’s font (the font has no glyph for one of
its characters, or isn’t embedded in the PDF), the job fails and its
error_message names the fields, so a value never goes missing from the
flattened PDF.
curl https://sync.api.docspring.com/api/v2/jobs/flatten_pdf \ -u "$DOCSPRING_TOKEN_ID:$DOCSPRING_TOKEN_SECRET" \ -H "Content-Type: application/json" \ -d '{ "input": { "type": "custom_file", "id": "cfi_1234567890abcdef01" } }'PDF to images
Section titled “PDF to images”pdf_to_images renders each of pages (default every page) as an image file,
up to 100 pages a job. For a longer PDF, run a job for each 100 pages.
format:png(the default) orjpg.dpi: 36 to 300. The default, 150, makes a Letter page 1275 by 1650 pixels.quality: forjpgonly (a 422 withpng), from 1 (smallest) to 100 (best). The default is 90.
Each image is named after its page (contract-page-3.png), and its pages is
that page. For a submission’s pages, use
POST /submissions/{submission_id}/generate_files
instead: its page images are free.
curl https://sync.api.docspring.com/api/v2/jobs/pdf_to_images \ -u "$DOCSPRING_TOKEN_ID:$DOCSPRING_TOKEN_SECRET" \ -H "Content-Type: application/json" \ -d '{ "input": { "type": "url", "url": "https://example.com/contract.pdf" }, "format": "jpg", "dpi": 100, "pages": "1-3" }'Images to PDF
Section titled “Images to PDF”images_to_pdf makes a PDF with one image on each page, in order. It takes
inputs, 1 to 100 PNG or JPEG images, instead of input. page_size is fit
(the default), which makes each page the size of its image, or letter,
legal, a3, a4 or a5, which puts each image on a page of that size,
turned to landscape for a wide image, and shrinks the image to fit when it’s
larger than the page.
curl https://sync.api.docspring.com/api/v2/jobs/images_to_pdf \ -u "$DOCSPRING_TOKEN_ID:$DOCSPRING_TOKEN_SECRET" \ -H "Content-Type: application/json" \ -d '{ "inputs": [ { "type": "url", "url": "https://example.com/scan-1.png" }, { "type": "url", "url": "https://example.com/scan-2.jpg" } ], "page_size": "a4" }'PDF to text
Section titled “PDF to text”pdf_to_text extracts the text of each of pages (default every page) into
one .txt file, in reading order. There’s no OCR, so a scanned page has no
text.
curl https://sync.api.docspring.com/api/v2/jobs/pdf_to_text \ -u "$DOCSPRING_TOKEN_ID:$DOCSPRING_TOKEN_SECRET" \ -H "Content-Type: application/json" \ -d '{ "input": { "type": "submission", "id": "sub_1234567890abcdef01" } }'HTML to PDF
Section titled “HTML to PDF”html_to_pdf converts a page of HTML and CSS to a PDF. Send the page as
html, or a file of it as input, with the page’s settings. The page can be up
to 10 MB either way. A file is read as HTML text, so the links in it (images,
stylesheets, fonts) must be absolute URLs.
page_size:Letter(the default),Legal,Tabloid,Ledger,CR80orA0toA6. For any other size sendwidthandheightinstead, such as4inand6in.landscape: turn the page on its side.margin:top,right,bottomandleft, each a length with a unit (in,cm,mmorpx). Each side’s default is1in.header_htmlandfooter_html: HTML printed in the top and bottom margins of every page. An element with the classpageNumber,totalPagesordategets the page’s number, the number of pages or today’s date. Give the text afont-size.print_background: print the page’s own background, whichhtmlorbodysets.
curl https://sync.api.docspring.com/api/v2/jobs/html_to_pdf \ -u "$DOCSPRING_TOKEN_ID:$DOCSPRING_TOKEN_SECRET" \ -H "Content-Type: application/json" \ -d '{ "html": "<html><head><style>h1 { color: #0b5fff; }</style></head><body><h1>Invoice 42</h1><p>Due on 1 November.</p></body></html>", "page_size": "A4", "margin": { "top": "20mm", "bottom": "20mm" }, "footer_html": "<p style=\"font-size: 9pt\">Page <span class=\"pageNumber\"></span> of <span class=\"totalPages\"></span></p>" }'The job makes one file, document.pdf, or a PDF named after the file you sent.
Images, stylesheets and fonts that the page links to are downloaded. The page
itself isn’t shown again in the job, and it’s deleted with the job’s files.
Engines
Section titled “Engines”engine chooses what converts the page:
standard(the default) is DocSpring’s own engine. It’s fast, and it doesn’t run JavaScript: a page with a<script>fails, with a message that says to use Chromium. A link it can’t download fails the job with a message naming it.chromiumprints the page with Chromium, which runs the page’s JavaScript first. It also takesscale, from 0.1 to 2.
curl https://sync.api.docspring.com/api/v2/jobs/html_to_pdf \ -u "$DOCSPRING_TOKEN_ID:$DOCSPRING_TOKEN_SECRET" \ -H "Content-Type: application/json" \ -d '{ "input": { "type": "url", "url": "https://example.com/report.html" }, "engine": "chromium", "scale": 0.8 }'To fill a page in with data, make it an HTML template and create submissions for it.
Markdown to PDF
Section titled “Markdown to PDF”markdown_to_pdf converts GitHub Flavored Markdown (tables, task lists,
strikethrough and raw HTML) to a PDF. Send it as markdown, or a file of it as
input, up to 10 MB either way. DocSpring’s stylesheet for Markdown styles it, and css is added
after that stylesheet, so its rules win. It takes the same page settings as
html_to_pdf.
curl https://sync.api.docspring.com/api/v2/jobs/markdown_to_pdf \ -u "$DOCSPRING_TOKEN_ID:$DOCSPRING_TOKEN_SECRET" \ -H "Content-Type: application/json" \ -d '{ "markdown": "# Meeting notes\n\n- [x] Budget approved\n- [ ] Hire a designer\n", "css": "h1 { font-family: Georgia, serif; }" }'Markdown is converted without JavaScript. For a page that needs it, convert
the page as HTML with engine chromium.
Signed PDFs
Section titled “Signed PDFs”A digital signature covers the file’s exact bytes, so it can’t stay valid in a
file a tool has written again. When the PDF has signed signature fields, the
tools that change it (split, extract, rotate, encrypt, decrypt,
watermark, page numbers, compress and flatten) remove those fields from the
files they make and leave each signature’s picture on its page, so a reader
doesn’t show the file as tampered with. compress_pdf leaves a PDF it can’t
make smaller untouched, signature included. pdf_to_images and pdf_to_text
only read the PDF. Keep the signed original when you need the signature itself.
Run one tool after another
Section titled “Run one tool after another”A job’s files can be the next job’s input. Split a PDF, then watermark its second part:
curl https://sync.api.docspring.com/api/v2/jobs/watermark_pdf \ -u "$DOCSPRING_TOKEN_ID:$DOCSPRING_TOKEN_SECRET" \ -H "Content-Type: application/json" \ -d '{ "input": { "type": "job", "id": "job_1234567890abcdef01", "file": 2 }, "text": "DRAFT" }'The first job must have finished. On sync.api.docspring.com each request
waits for its job, so send them one after another.
Errors
Section titled “Errors”A request that DocSpring can’t run returns an error, and no job is created:
422validation_failed: an option or input isn’t valid. Each item indetailshas apointerto the value, such as/rangesor/input/id. An input that isn’t found has the codenot_found.402insufficient_credits: your balance can’t cover the job. Add credits on the Billing page, then send the request again. Unlike submissions, jobs don’t wait for credits.403upgrade_required: the account is on a plan purchased before prepaid credits were introduced, which doesn’t include the PDF tools. Switch to a current plan on the Billing page, or contact support if the page doesn’t offer the switch.429rate_limited: the account already has 100 jobs waiting to run. Wait for theRetry-Afterheader’s seconds, then send the request again.
{ "error": { "code": "validation_failed", "message": "Invalid request: /input/id There's no submission sub_1234567890abcdef01.", "details": [ { "code": "not_found", "message": "There's no submission sub_1234567890abcdef01.", "pointer": "/input/id" } ], "request_id": "req_1234567890abcdef01" }}A job that ran and failed has state: "error" and an error_message that says
what to change: a page the PDF doesn’t have, a file that isn’t a PDF, a wrong
password, text the font can’t draw, or a split that would make more than 100
files.
A tool runs for up to 5 minutes. An HTML or Markdown conversion runs for up to 45 seconds on the Standard engine and 90 seconds on Chromium. A job that reaches that fails, and uses credits for the time it ran. Run it on fewer pages, split the PDF first, or convert a shorter document.
Expiry and deleting
Section titled “Expiry and deleting”A job’s files are deleted when it expires, at its expires_at: expires_in
seconds after it finishes, or else after the length of your account’s
expiry setting for the PDF tools
(a day for new accounts). With that setting off, expires_at is null and the
files are kept until you delete the job. Once a job has expired, expired is true and files is empty. A job that
fails is kept for at least 48 hours. To delete a job’s files sooner, delete the
job:
curl -X DELETE https://sync.api.docspring.com/api/v2/jobs/job_1234567890abcdef01 \ -u "$DOCSPRING_TOKEN_ID:$DOCSPRING_TOKEN_SECRET"This deletes the job’s files, its metadata and its inputs’ URLs now, and returns the expired job. Its ID, state and credits stay.
GET /jobs lists your jobs, newest first. Add
?operation=split_pdf to list one tool’s jobs.
Credits
Section titled “Credits”A job uses 1 credit per unit. A unit is up to 10 pages, 10 MiB of input
files, 20 seconds of processing or 50 MiB of output files, whichever is the
most units, and a job is at least 1 unit. Most jobs use 1 credit. A job’s
credits shows what it used.
A job’s files include 30 days of storage. A job you keep for longer counts as one stored document, with the size of all its files. A job that expires within 30 days has no storage charge.
Jobs have no test mode: a job made with a test API token uses credits like a live one, and its files have no watermark.
The PDF tools need one of our current plans. An account on a plan purchased before prepaid credits were introduced can’t run them until its owner switches plans on the Billing page, or through support when the page doesn’t offer the switch. Combine PDFs works as before on every plan.