Run stages
Runs a list of stages on the PDFs you upload, in order.
curl \
--request POST http://localhost:3000/forms/pdf/pipe \
--form files=@report.pdf \
--form 'stages=[
{ "op": "select", "pages": "1-2" },
{ "op": "stamp-text", "text": "DRAFT", "x": 72, "y": 72, "fontSize": 24 },
{ "op": "optimize" }
]' \
-o report.pdf
How stages work
- Each stage works on what the previous one produced, so its page numbers count from that PDF.
- The stages take the PDFs in the alphanumeric order of their names.
- A stage names the files it needs, such as an image to stamp or a certificate, by their uploaded names. Upload them under
files: they don't count as PDFs to process. stagesworks on this route and on the Chromium and LibreOffice conversions, where the stages run on the converted PDFs. The screenshot routes, the stages' own routes and the read routes answer 400 to it.- Each stage also has its own route,
/forms/pdf/<op>, which takes its options as form fields, with a list or an object as JSON.
Every stage
| Stage | What it does |
|---|---|
merge | Appends the PDFs into one, in the alphanumeric order of their names. The result takes the name of the first. |
split | Cuts each PDF into several, which come back in a ZIP: report_0.pdf, report_1.pdf… The stages after it run on each part. |
select | Keeps the pages you list, in the order you list them. |
delete | Removes the pages you list. |
insert | Inserts the pages of another uploaded PDF. |
compose | Draws pages of the PDFs on new pages of the size you choose: a label, a packing slip, a sheet of several pages. The result is one new PDF, named after the first. |
rotate | Sets the rotation of pages. Viewers turn them clockwise. |
stamp-text | Draws a line of text over pages. |
stamp-image | Draws an uploaded PNG or JPEG image over pages. |
stamp-pdf | Draws a page of another uploaded PDF over pages: a letterhead, a seal. |
set-metadata | Writes the document information. A field you leave out keeps its value. |
clear-metadata | Removes the document information and the XMP metadata. The PDF is rewritten, so the old values do not remain in the file. |
set-bookmarks | Replaces the bookmarks, the outline viewers show beside the pages. |
set-form | Fills form fields. |
flatten-form | Burns the form fields into the pages, which can then no longer be edited. A value without a stored appearance is drawn, with an installed font for text outside Western European. |
flatten-transparency | Replaces transparent content with opaque content, for printers and archival formats that don't support transparency. |
convert-colors | Converts every color to one color space. |
redact | Removes the content under each region from the file itself, not just from view. Nothing is drawn in its place. |
autotag | Infers a structure tree for an untagged PDF, so screen readers can follow it. PDF/UA requires one. |
attach | Embeds an uploaded file in the PDF. |
detach | Removes an embedded file. |
extract-attachments | Returns the embedded files, which come back in a ZIP next to the PDF: invoice_factur-x.xml. /forms/pdf/extract-attachments returns the files alone. Comes last. |
extract-text | Returns the text the pages show as a .txt file, its pages separated by a form feed, or as a Markdown .md file, which comes back in a ZIP next to the PDF: report.txt. /forms/pdf/extract-text returns the text alone. Comes last. |
optimize | Rewrites the PDF to shrink it. Every option is on unless you turn it off. A signed PDF answers 400 unless dropSignatures is on, and an encrypted one unless the stages decrypt or encrypt it. |
encrypt | Protects the PDF with passwords. |
decrypt | Opens encrypted PDFs and removes their encryption. |
remediate | Repairs the PDF until it conforms to a profile, or to a PDF/A profile and a PDF/UA one together. Gotenberg-Remediation-Residual counts the violations left: 0 means it conforms. |
sign | Signs the PDF with a certificate you upload. |
timestamp | Adds a document timestamp from an RFC 3161 timestamp authority: proof the PDF existed, unchanged, at that time. |
render | Draws pages as images, which come back in a ZIP next to the PDF: report_1.png. /forms/pdf/render returns the images alone. |
Order rules
Gotenberg checks the order of the stages before it runs any, and answers 400 with the rule a list breaks:
decryptcomes first, andrender,extract-attachmentsorextract-textlast.- A list has at most one
remediate, oneencrypt, onesignand onetimestamp. Oneremediatetakes a PDF/A profile and a PDF/UA one together. - After
remediate, onlyencrypt,optimize,sign,timestamp,render,extract-attachmentsandextract-textmay follow. - After
encrypt, onlyoptimize,render,extract-attachmentsandextract-textmay follow. - After
signortimestamp, onlysign,timestamp,render,extract-attachmentsandextract-textmay follow. encryptdoesn't combine withsign,timestamp, or a PDF/A or Factur-Xremediate.decryptdoesn't combine withsignortimestamp: sign the decrypted PDF in a request of its own.
What each stage does to the file
A stage either rewrites the PDF whole or appends an update to it. A signature covers the bytes of the file it was made in, so a rewrite can't keep it: on a signed PDF, those stages answer 400 unless they set dropSignatures, which removes the signatures and keeps their visible appearance on the page. Gotenberg decides on the file it writes: a remediate that only appends its repairs keeps the signatures and needs no option.
| The file | Stages |
|---|---|
| Rewritten, signatures dropped | select, delete, insert, merge, split, compose, encrypt, decrypt, clear-metadata, flatten-form, redact, remediate, convert-colors, flatten-transparency, optimize |
| Updated, signatures kept | rotate, stamp-text, stamp-image, stamp-pdf, set-form, set-metadata, set-bookmarks, attach, detach, autotag, sign, timestamp |
| Unchanged | render, which makes images, extract-attachments, which returns the embedded files, and extract-text, which returns the text |
Page selections
An option of type pages takes a comma-separated list of parts: a page (3), a range (2-5), a range open to the last page (3-) or from the first (-3), or odd, even or last. A ! in front of a part excludes its pages: !1 keeps every page but the first, odd,!1 the odd pages after it, and !last every page but the last. Without an inclusion, the selection starts from every page. Pages count from 1. A page past the end, or a selection that leaves no page, answers 400. all, on its own, names every page.