Booklet Imposition (8/16 Page)
Relevant source files
The following files were used as context for generating this wiki page:
The Booklet Imposition system is a specialized document processing module designed to reorder and duplicate PDF pages for professional printing. Its primary purpose is to convert standard sequential PDFs into imposed layouts suitable for creating A5 or A6 booklets on A3 or A4 paper sheets, supporting both double-sided (duplex) and single-sided (simplex) printing.
This system automates complex pagination math, ensuring that when printed sheets are folded or cut and stacked, the pages appear in the correct numerical order. It integrates features such as crop mark generation, gutter management, and automatic page padding to ensure the final document meets printing industry standards for booklets and leaflets.
Sources: app/README.md, app/models/imposition.php:12-28, app/translations/en.json
System Architecture and Logic
The imposition logic is divided into two primary modes: Brochure Mode (for folded booklets) and Book/Livre Mode (Cut & Stack). The architecture relies on the setasign/Fpdi library to import existing PDF pages and the TCPDI class to generate the new layout.
Imposition Workflow
The following diagram illustrates the high-level process from file upload to the generation of the imposed PDF.
Page Reordering (Pagination)
To create a booklet, the system must calculate specific "multiples" for padding. For a standard 2-up imposition, the page count must be a multiple of 4. For 4-up, it must be a multiple of 8, and for 8-up, it must be a multiple of 16.
- Padded PDF Function:
padPdfToMultiple($pdfFilePath, $multiple)ensures the source file has enough pages by adding blank ones at the end. - Duplex Logic: In
Cut & Stackmode, the system calculates astackDepth(total physical sheets). It uses a mirror logic for the "Verso" (back) side to ensure pages align perfectly when printed double-sided.
Sources: app/models/imposition_brochure.php:15-20, app/models/imposition.php:57-75
Key Components and Configuration
Imposition Parameters
The system accepts various settings to control the output format and physical dimensions of the imposed pages.
| Parameter | Type | Default | Description |
|---|---|---|---|
n_up | Integer | 2 | Number of poses per side (2, 4, or 8). |
output_format | String | "A3" | Physical paper size (A3 or A4). |
duplex | Boolean | true | Enables Recto-Verso ordering. |
scale | Float | 100 | Percentage scaling of original pages. |
gutter_strategy | String | "reduce" | Strategy if space is insufficient: "reduce" (scale down) or "crop". |
crop_marks | Boolean | false | Adds trimming guides to the output. |
Sources: app/models/imposition.php:15-30, app/view/imposition_brochure.html.php:185-230
Geometric Calculations
The placePage method in app/models/imposition.php handles the precise placement of each imported page on the new sheet. It calculates the scaleFactor based on target width/height or percentage, manages global centering, and applies gutters.
Sources: app/models/imposition.php:123-160
Advanced Features
Ghostscript Fallback
If the standard PHP library fails to parse a PDF (often due to version incompatibilities), the system executes a shell command to "clean" the PDF using Ghostscript. This process normalizes the PDF to version 1.4 with a /printer setting.
Sources: app/models/imposition_brochure.php:248-262, app/models/imposition_livre.php:246-260
Visual Guides and Previews
- Preview Mode: Generates a version of the PDF with red page numbers on yellow backgrounds to help users verify the sequence before final printing.
- Crop Marks: The
drawSmartCropMarksfunction renders lines at the corners of each "cut" area, accounting for bleed and gutter offsets. - Gutter Pagination: Optional small page numbers can be added specifically within the gutters to assist in manual sorting/folding.
Sources: app/models/imposition.php:200-245, app/models/imposition_brochure.php:66-85
Sequence of Execution (User Interaction)
Conclusion
The Booklet Imposition module provides a robust set of tools for creating professional print layouts. By combining flexible grid options (2/4/8-up), intelligent gutter strategies, and a resilient Ghostscript-backed processing chain, it successfully addresses common challenges in small-scale publishing and reproduction collectives. It ensures technical accuracy in pagination while offering the visual feedback necessary for print production.
Sources: app/README.md, app/models/imposition.php:1-10