Feature Request: Support PDF page composition into a single custom-sized page
Summary
It would be useful if Gotenberg could support composing multiple PDF pages into a single new PDF page with a custom size and position, rather than only merging PDFs as separate pages.
This is different from the current PDF merge behavior.
For example, I have:
- PDF A:
6 × 2 - PDF B:
6 × 3
I would like to produce a single-page PDF with a size of 6 × 5:
┌─────────────────┐
│ │
│ PDF A 6 × 2 │
│ │
├─────────────────┤
│ │
│ PDF B 6 × 3 │
│ │
└─────────────────┘
6 × 5In this example:
- PDF A is placed at
x=0, y=3 - PDF B is placed at
x=0, y=0 - Both PDFs are kept at their original size (
scale = 1) - No cropping or distortion is required
- The output contains one page, not two pages
Existing pdfcpu capability
This seems particularly relevant because Gotenberg already integrates pdfcpu as a PDF engine.
pdfcpu already supports using a PDF as a stamp and provides options for positioning, offset, scaling, rotation, and stacking multiple PDF stamps. This appears to provide much of the underlying functionality required for page composition.
Gotenberg already exposes pdfcpu-backed PDF stamping through /forms/pdfengines/stamp, including PDF sources and options such as scale, offset, and rotation.
However, the current stamp API applies content on top of an existing page. What is missing is a way to create a new canvas/page with a custom size and compose multiple PDF pages onto that canvas.
Proposed feature
I would suggest adding a PDF composition operation, for example:
POST /forms/pdfengines/composeor extending the existing PDF engine API with a composition mode.
Conceptually, the request could look like:
{
"width": 6,
"height": 5,
"unit": "in",
"pages": [
{
"file": "a.pdf",
"page": 1,
"x": 0,
"y": 3,
"scale": 1,
"rotation": 0
},
{
"file": "b.pdf",
"page": 1,
"x": 0,
"y": 0,
"scale": 1,
"rotation": 0
}
]
}Potentially, the composition API could support:
- custom output page size
- arbitrary
x/ypositioning - scaling
- rotation
- multiple source PDFs
- selecting individual source pages or page ranges
- optional clipping
- preserving the source page size at
scale = 1
Why this would be useful
This would cover use cases such as:
- label printing
- shipping labels
- packing slips
- warehouse documents
- receipts
- print layouts
- custom N-up layouts
- page tiling
- PDF imposition
- combining PDF pages with different dimensions into one physical page
For example:
6 × 2 PDF
+
6 × 3 PDF
↓
6 × 5 single-page PDFThis is especially useful for printing workflows where the final PDF page needs to match a physical paper or label size.
Difference from PDF merge
The current merge operation produces:
PDF A page
PDF B pageas separate pages in one PDF.
The requested operation would instead produce:
┌─────────────────┐
│ PDF A │
├─────────────────┤
│ PDF B │
└─────────────────┘as one new PDF page.
Possible implementation direction
Since Gotenberg already uses pdfcpu for PDF manipulation, it may be possible to build this feature on top of the existing pdfcpu integration rather than introducing another PDF engine.
The main missing abstraction appears to be a new output canvas/page plus arbitrary placement of imported PDF page content.
Thanks for considering this feature!
Source: gotenberg/gotenberg