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.
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.
sourcenames the uploaded PDF to draw from. Leave it out when you upload one PDF.sourcePagepicks the page ofsource,1by default.scaleresizes the page,1by default, and must be greater than 0.rotationturns the page, in degrees counter-clockwise aroundxandy.
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