Image & PDF Conversions
Relevant source files
The following files were used as context for generating this wiki page:
The Image & PDF Conversions module provides essential tools for transforming documents between portable formats (PDF) and raster images (PNG/JPG). This functionality is integrated into the Duplicator collective reproduction management system to facilitate prepress tasks such as page extraction, document assembly, and image enhancement for Riso or photocopier printing.
The system utilizes server-side PHP processing—leveraging tools like Ghostscript and TCPDF—alongside client-side JavaScript enhancements (PDF.js and Riso Tools) to provide real-time previews and efficient file handling. Users can upload files directly or select them from the internal document library.
Sources: app/README.md, app/models/pdf_to_png.php:1-10, app/view/image_processor.html.php:1-15
## PDF to Image Extraction
The system allows users to extract individual pages from a PDF document as high-quality PNG images. This is primarily handled by the convert_pdf_to_png function, which invokes Ghostscript (gs) to perform the rasterization.
### Logic and Execution
The backend logic validates the PDF file, creates a temporary directory in the system's temp folder, and executes a shell command to Ghostscript. The output is a series of PNG files named sequentially (e.g., page_001.png).
The conversion quality is configurable via Dots Per Inch (DPI) settings:
| Quality Level | DPI Value | Description |
|---|---|---|
| Low | 72 | Fast processing, lightweight files |
| Medium | 150 | Balanced quality and size |
| High | 300 | Print-ready, high-quality images |
Sources: app/models/pdf_to_png.php:8-45, app/view/pdf_to_png.html.php:75-95
### Key Components
- Function:
convert_pdf_to_png($pdf_file, $output_dir, $dpi, $base_filename) - Backend dependency: Ghostscript (
gswin64c.exeon Windows orgson Linux). - Storage: Uses
sys_get_temp_dir()to ensure compatibility with AppImage and portable environments.
Sources: app/models/pdf_to_png.php:10-20, app/public/index.php:40-45
## Image to PDF Assembly
The inverse process allows users to take multiple PNG or JPG images and combine them into a single PDF document. This is useful for creating print runs from scanned artworks or digital designs.
### Technical Implementation
This feature uses the TCPDF library to generate the document. Each image is placed on a new page, automatically scaled to fit the chosen page format (A3 or A4) while maintaining the original aspect ratio.
### Configuration Options
| Parameter | Values | Impact |
|---|---|---|
| Format | A4, A3 | Defines the physical dimensions of the PDF pages |
| Orientation | Portrait (P), Landscape (L) | Defines the vertical or horizontal layout |
| Scaling | Automatic | Images are scaled to min(widthRatio, heightRatio) to fit without cropping |
Sources: app/models/png_to_pdf.php:8-50, app/view/png_to_pdf.html.php:60-90
## Advanced Image Processing
Beyond simple conversion, the system includes an Image Processor for prepping images specifically for Riso printing. It combines server-side persistence with client-side real-time manipulation.
### Core Processing Capabilities
The processor handles adjustments for Contrast, Brightness, Gamma, and Saturation. It also includes a specialized Bitmap/Dithering mode to convert images into high-contrast black and white, which is a requirement for creating Riso masters.
### Specialized Prepress Tools
The system includes riso-tools.js, a library providing:
- Halftone Taming: Converts gradients into dot patterns (Bayer matrix 8x8) to simulate traditional printing screens.
- Color Separation: Extracts RGB or CMYK channels into individual grayscale layers.
- Dithering: Implements the Floyd-Steinberg algorithm for error diffusion in B&W conversions.
Sources: app/public/js/riso-tools.js:235-300, app/view/image_processor.html.php:120-180, app/public/js/riso-tools.js:400-420
## Integration with Document Library
All conversion tools are integrated with the BibliothequeManager. Users do not need to upload files repeatedly; they can select an existing file from the library, which is passed via lib_file_id to the conversion models.
- PDF to PNG: Can be triggered via
?pdf_to_png&from_lib=[ID]. - PNG to PDF: Can be triggered via
?png_to_pdf&from_lib=[ID]. - Image Processor: Automatically loads files from the library into the preview canvas using a fetch request to
?get_bibliotheque_file.
Sources: app/models/pdf_to_png.php:60-75, app/view/image_processor.html.php:185-200, app/public/index.php:280-290
## Conclusion
The Image & PDF Conversion module serves as the primary prepress bridge in the Duplicator application. By combining the robust document generation capabilities of TCPDF and Ghostscript with the interactive image processing of riso-tools.js, the system provides a comprehensive workflow for transforming digital files into print-ready assets. The implementation ensures that resources are handled securely within temporary system directories, making it compatible with various deployment environments.