Tract Imposition
Relevant source files
The following files were used as context for generating this wiki page:
Tract Imposition (also referred to as Flyer Imposition) is a specialized document processing module within the Duplicator application. Its primary purpose is to automate the duplication and optimization of flyers (tracts) by placing multiple copies of a source PDF onto a larger sheet of paper, typically A3 or A4, to maximize printing efficiency.
The module features automatic format detection for standard sizes like A4, A5, and A6, and intelligently calculates the optimal layout—such as placing 2x A4, 4x A5, or 8x A6 flyers on a single A3 sheet. It supports both single-sided and duplex flyers, handles non-standard formats through manual overrides, and provides high-quality output via Ghostscript cleaning and TCPDF/FPDI processing.
Sources: app/translations/en.json:442-450, README.md:28-36
System Architecture and Workflow
The system follows a Model-View-Controller (MVC) pattern where the logic is divided between the view template for user interaction and a model for PDF manipulation.
Technical Workflow
The imposition process begins with a user uploading a PDF or selecting one from the library. The backend performs a multi-step validation and cleaning process using Ghostscript before the final layout is generated.
The system ensures compatibility by using Ghostscript to convert incoming PDFs to a standard 1.4 compatibility level before processing.
Sources: app/models/imposition_tracts.php:123-146, app/models/imposition_tracts.php:218-243
Key Features and Components
Format Detection and Optimization
The module automatically detects the dimensions of the input PDF to categorize it into standard paper sizes.
| Source Format | Target Sheet | Copies per Sheet | Orientation |
|---|---|---|---|
| A4 | A3 | 2 | Landscape |
| A5 | A3 | 4 | Portrait (Optimized) |
| A6 | A3 | 8 | Landscape |
| A5 | A4 | 2 | Portrait |
| A6 | A4 | 4 | Landscape |
Sources: app/models/imposition_tracts.php:394-428, app/models/imposition_tracts.php:455-498
PDF Analysis Logic
The analyzePDFFormat function serves as the primary diagnostic tool. It imports the first page of the PDF using FPDI and measures the template size in millimeters to determine the format.
function determineFormat($widthMm, $heightMm)
{
$formats = [
'A4' => [210, 297],
'A5' => [148, 210],
'A6' => [105, 148]
];
foreach ($formats as $format => $dimensions) {
if (($widthMm === $dimensions[0] && $heightMm === $dimensions[1]) ||
($widthMm === $dimensions[1] && $heightMm === $dimensions[0])) {
return $format;
}
}
return 'unknown';
}
Sources: app/models/imposition_tracts.php:165-188, app/models/imposition_tracts.php:191-209
Core Implementation Details
The Imposition Engine
The performImposition function handles the physical placement of pages. It calculates "slots" on the target sheet based on the calculated rows and columns, accounting for spacing and margins.
- Slot Calculation: Determines the grid (e.g., 2 columns x 4 rows for 8 copies of A6 on A3).
- Transformation: Supports
force_resizeto stretch content to fill slots orkeep_original_sizeto center the original flyer within the slot. - Crop Marks: Utilizes a helper class
CropMarksto draw cutting guides around each flyer pose based on user-defined length and thickness.
Sources: app/models/imposition_tracts.php:445-560, app/view/imposition_tracts.html.php:137-160
Processing Sequence
The following sequence diagram illustrates the communication between the browser interface and the server-side imposition logic during a file analysis request.
User Interface and Configuration
The user interface, located in app/view/imposition_tracts.html.php, provides a drag-and-drop area for PDF uploads. Users can configure the following parameters:
- Manual Format Override: Allows selection of A4, A5, or A6 if automatic detection fails.
- Resizing Options: A checkbox to "Force resize if the format differs" from the target slot.
- Crop Margin: Adjustable margin (e.g., 0, 2, 3, or 5 mm) to provide bleed space between duplicated poses.
- Output Sheet Settings: Selection between A3 or A4 paper and Landscape/Portrait/Auto orientation.
- Crop Marks Customization: Detailed inputs for mark length and thickness.
Sources: app/view/imposition_tracts.html.php:86-180, app/translations/en.json:442-490
Conclusion
Tract Imposition is a robust utility that bridges the gap between digital design and physical duplication. By leveraging Ghostscript for pre-processing and FPDI for template-based imposition, it provides a reliable way to optimize paper usage while ensuring that both simple and complex (duplex) flyers are positioned accurately for mass production on Riso duplicators or photocopiers.