Compose PDFs
Recipe can append pages from another PDF, insert a selected page, overlay a PDF on an edited page, or split a document into separate output files.
var pdfDoc = new Recipe("input.pdf", "output.pdf");
pdfDoc
.appendPage("appendix.pdf", 10)
.appendPage("appendix.pdf", [4, 6])
.appendPage("appendix.pdf", [
[1, 3],
[6, 20],
])
.insertPage(2, "cover.pdf", 1)
.endPDF();
Page numbers passed to Recipe composition methods are positive, one-based
integers. Omitting the page selection from appendPage appends all pages;
inclusive range pairs must be ascending, and endpoints beyond the source clamp
to its final page. Pass all three insertPage arguments together.
To overlay another PDF, edit the target page first:
The overlay options support placement, scaling, page selection, aspect-ratio
preservation, and fit-to-width or fit-to-height behavior. To place a page like an image,
with alignment, rotation, or a frame, pass the PDF to image(); see
Place and Transform Images. To split a PDF, open
it without an output file and call split(outputDirectory, prefix) before
endPDF().