Skip to main content
Version: 9.x

Compose pages

Draws pages of the uploaded PDFs on new pages of the size you choose: a label, a packing slip, a sheet of several pages.

POST/forms/pdf/compose
filesfile[]required

The PDFs.

archivesfile[]

ZIP files Gotenberg unpacks: each entry counts as a file uploaded under files.

URLs Gotenberg downloads first, as if you had uploaded the files. Each entry takes a url, and optionally extraHttpHeaders and filename.

paperSizestring

A0, A1, A2, A3, A4, A5, B4, B5, Letter, Legal or Tabloid, in any case. Sets the width and the height. Set paperSize, or paperWidth and paperHeight.

Overrides the width paperSize sets. A length is a number in inches, or a number with a unit: 6in, 15cm, 152mm, 432pt, 576px, 36pc.

Overrides the height paperSize sets.

placementslistrequired

Items with a source, the uploaded PDF to draw from, which may be left out with one PDF; a sourcePage, 1 by default; a page, the new page to draw on, 1 by default; x and y, in points from the bottom-left corner, 0 by default; a scale, 1 by default; and a rotation, in degrees counter-clockwise around x and y, 0 by default. Every uploaded PDF must be placed.

Removes the signatures of a signed PDF, which this stage rewrites, and keeps their visible appearance on the page. Without it, a signed PDF answers 400.

Default: false

One PDF.

The route also takes the headers. An error answers a status and a message: see Errors.

curl \
--request POST http://localhost:3000/forms/pdf/compose \
--form files=@report.pdf \
--form files=@annex.pdf \
--form paperWidth=6in \
--form paperHeight=5in \
--form 'placements=[
{ "source": "report.pdf", "x": 0, "y": 180, "scale": 0.25 },
{ "source": "annex.pdf", "x": 0, "y": 0, "scale": 0.25 }
]' \
-o label.pdf

The answer is one 6 by 5 inch page: the first page of report.pdf on the top half, the page of annex.pdf on the bottom half, each at a quarter of its size.

Size the page​

paperSize takes A0, A1, A2, A3, A4, A5, B4, B5, Letter, Legal or Tabloid, in any case. paperWidth and paperHeight take a length: a number with a unit, pt, px, in, mm, cm or pc, such as 432pt or 15cm. A bare number is in inches. paperWidth or paperHeight overrides the side paperSize sets, so paperSize: "A4" with paperHeight: "5in" gives an A4-wide page 5 inches tall.

curl \
--request POST http://localhost:3000/forms/pdf/compose \
--form files=@report.pdf \
--form paperSize=A4 \
--form 'placements=[
{ "x": 20, "y": 231, "scale": 0.6 },
{ "sourcePage": 2, "x": 307, "y": 231, "scale": 0.6 }
]' \
-o report.pdf

A request without paperSize, or without paperWidth and paperHeight, answers 400. So does a side outside 3 to 14,400 points, the sizes a PDF page allows.

Place pages​

Each placement draws one page. Its x and y count in points from the bottom-left corner of the new page, 72 points to the inch, like a stamp's. They set where the bottom-left corner of the drawn page goes.

  • source names the uploaded PDF to draw from. Leave it out when you upload one PDF.
  • sourcePage picks the page of source, 1 by default.
  • scale resizes the page, 1 by default, and must be greater than 0.
  • rotation turns the page, in degrees counter-clockwise around x and y.

Gotenberg draws the page as a viewer shows it: its crop box, turned by its rotation. Placements draw in order, so a later placement paints over an earlier one where they overlap.

Every uploaded PDF must be placed, at least one of its pages. A PDF no placement names, or a source that names no uploaded PDF, answers 400:

Stage 'compose' failed on 'annex.pdf': "placements" must place every uploaded PDF: "report.pdf" is not placed
Stage 'compose' failed on 'annex.pdf': "source" must name an uploaded PDF, got "nope.pdf"; the uploaded PDFs are annex.pdf, report.pdf

The PDFs come in the alphanumeric order of their names, as for a merge. The result takes the name of the first PDF: annex.pdf in the first example.

Several pages​

page picks the new page a placement draws on, 1 by default. The PDF has as many pages as the highest page names:

curl \
--request POST http://localhost:3000/forms/pdf/compose \
--form files=@report.pdf \
--form paperSize=A5 \
--form 'placements=[
{ "sourcePage": 1, "page": 1, "scale": 0.9 },
{ "sourcePage": 3, "page": 2, "scale": 0.9 }
]' \
-o report.pdf

A page no placement names comes out blank: a placement with page: 3 and none with page: 2 leaves the second page empty.

What is not drawn​

The annotations and form fields of the source pages are not drawn: links, comments and field values stay behind. The sources' bookmarks, tags and metadata stay behind too. The result is a new, untagged PDF. Add set-metadata, set-bookmarks or autotag stages after compose to give it its own.

In a list of stages​

The stage also runs in a list on /forms/pdf/pipe, and on the PDFs a Chromium or LibreOffice conversion makes, in its stages field:

curl \
--request POST http://localhost:3000/forms/pdf/pipe \
--form files=@report.pdf \
--form files=@annex.pdf \
--form 'stages=[
{ "op": "compose", "paperWidth": "6in", "paperHeight": "5in", "placements": [ { "source": "report.pdf", "x": 0, "y": 180, "scale": 0.25 }, { "source": "annex.pdf", "x": 0, "y": 0, "scale": 0.25 } ] }
]' \
-o label.pdf