A powerful ProcessWire module for generating PDF documents from pages with full support for UTF-8/Cyrillic characters, multiple fonts, and all ProcessWire field types including ProFields.
Features
- PDF Generation: Convert any ProcessWire page to PDF
- Multiple Engines: Support for mPDF (recommended) and Dompdf
- Full Field Support: All native ProcessWire fields plus ProFields (Table, Repeater, RepeaterMatrix, Combo)
- Typography: 14 font options including DejaVu Sans for multilingual support
- Customization: Configurable margins, paper sizes, headers, footers, and watermarks
- Security: PDF password protection and permission restrictions
- Image Handling: Automatic filtering of external images that can't be embedded
- Smart Detection: Handles single and multiple values for images, files, and pages
- UTF-8 Support: Full support for Cyrillic and other international characters
Requirements
- ProcessWire 3.0 or later
- PHP 8.0 or later
- Composer
- mPDF library (recommended) or Dompdf
Installation
Method 1: Composer in Module Directory (Recommended)
This method keeps all dependencies contained within the module folder.
- Clone the repository into
/site/modules/:cd /site/modules git clone https://github.com/mxmsmnv/WirePDF.git - Install dependencies:
cd WirePDF composer install
- Go to Modules → Refresh
- Click Install next to WirePDF
Method 2: Global Composer (Legacy)
Install dependencies in the root vendor directory:
cd /path/to/your/processwire composer require mpdf/mpdf
Then install the module as usual.
Verify Installation
After installation, go to Setup → Modules → WirePDF and check the Library Status section to confirm mPDF is installed correctly.
Optional: Install Dompdf
If you want to use Dompdf as an alternative engine:
cd /path/to/your/processwire/site/modules/WirePDF composer require dompdf/dompdf
Setup
Create PDF Generator Template
Create a new template file: /site/templates/pdf-generator.php
Copy the complete pdf-generator.php code into this file.
Create PDF Page
- Create a new page (e.g.,
/pdf/) - Assign the
pdf-generatortemplate - Access via:
https://yoursite.com/pdf/?id=1234
Configuration
Go to Setup → Modules → WirePDF to configure:
Library Status
View the installation status of PDF libraries:
- mPDF: Installed or Not installed with installation command
- Dompdf: Installed or Not installed (optional) with installation command
Paper Settings
- Paper Size: A3, A4, A5, Letter, Legal, Ledger
- Orientation: Portrait or Landscape
Margins (mm)
- Top, Right, Bottom, Left
- Header, Footer
Typography
- Default Font: 14 options including:
- DejaVu Sans (recommended for multilingual)
- Helvetica, Arial, Times New Roman
- Monospace fonts (Courier, etc.)
- Font Size: 6-24pt
Header & Footer
- Enable/disable header and footer
- Custom text with variables:
{PAGENO}- Current page number{nbpg}- Total pages{DATE}- Current date (format: dd.mm.yyyy){sitename}- Your site domain
Example footer: Page {PAGENO} of {nbpg} | {DATE} | {sitename}
Images
- Enable/disable images in PDF
- Image DPI (72-300)
Watermark
- Custom watermark text
- Opacity (0.0-1.0)
Security
- PDF password protection
- User and owner passwords
- Restrict copying and printing
Debug & Logging
- Debug Mode: Enable detailed error messages on PDF generation failure
- Enable Logging: Toggle logging on/off to control log entries
- Log Location: ProcessWire Logs (Setup > Logs > wirepdf)
What gets logged:
- All essential generation info in single-line format
- Page information, template, filename, settings, execution time
- Success/failure status with clear indicators ([ok]/[fail])
- Errors and exceptions with details
Viewing logs:
- Go to Setup > Logs in ProcessWire admin
- Click on wirepdf log
- View all PDF generation events with timestamps
Example log output:
[ok] PDF Generated | Palette (ID: 1220) | Template: palette | File: palette.pdf | Paper: Letter/portrait | Engine: mpdf | Time: 0.007s
[ok] PDF Generated | Page Not Found (ID: 27) | Template: error404 | File: page-not-found.pdf | Paper: Letter/portrait | Engine: mpdf | Time: 0.511s
[fail] PDF Failed | ErrorPage (ID: 404) | Time: 1.234sBest practices:
- Production: Disable logging to reduce log entries
- Development: Enable logging when debugging generation issues
- Monitoring: Check ProcessWire logs regularly for errors and performance issues
Usage
Basic Usage
// Generate PDF from any page
$page->toPdf([
'filename' => 'my-document.pdf'
]);Custom Options
$page->toPdf([
'filename' => 'report.pdf',
'paper_size' => 'A4',
'orientation' => 'landscape',
'margin_top' => 30,
'margin_bottom' => 30,
]);Using Custom HTML
$html = '<h1>Custom Report</h1><p>Content here...</p>';
$page->toPdf([
'html' => $html,
'filename' => 'custom-report.pdf'
]);Using Custom Template
$page->toPdf([
'template' => 'pdf-invoice.php',
'filename' => 'invoice.pdf'
]);Save to File
$pdfModule = $modules->get('WirePDF');
$pdfModule->savePdf(
$page,
'/path/to/document.pdf',
['paper_size' => 'Letter']
);URL Parameters
Access PDFs via URL:
https://yoursite.com/pdf/?id=1234Where 1234 is the page ID you want to convert.
Supported Field Types
Native Fields
- Text - Single line text
- Textarea - Multi-line text
- CKEditor - Rich text with HTML
- Image - Single and multiple images
- File - File lists with sizes
- Page - Page references (single/multiple)
- Datetime - Formatted dates
- Checkbox - Yes/No
- URL - Web addresses
- Email - Email addresses
ProFields
- Table - Rendered as HTML tables
- Repeater - All repeater items with fields
- RepeaterMatrix - Matrix types with labels
- Combo - All combo subfields
Default Configuration
Paper Size: Letter (8.5 × 11in)
Orientation: Portrait
Margins: Top/Bottom 20mm, Left/Right 10mm
Header/Footer margins: 10mm
Font: Helvetica, 12pt
Footer: {PAGENO} / {nbpg}
Images: Enabled (96 DPI)
Logging: EnabledExternal Images
External images (from other websites) are automatically removed from PDFs as mPDF cannot access them. Only local images from your site are included.
Variables Reference
Header/Footer Variables
| Variable | Description | Example |
|---|---|---|
{PAGENO} | Current page number | 1, 2, 3... |
{nbpg} | Total pages | 5 |
{DATE} | Current date | 04.10.2025 |
{sitename} | Your domain | yoursite.com |
Troubleshooting
Blank PDF Generated
Cause: mPDF cannot parse complex CSS or external resources
Solution:
- Check ProcessWire logs (Setup > Logs > wirepdf) for errors
- Enable Debug Mode in module settings
- Simplify your HTML/CSS
- Remove external images
Images Not Showing
Cause: External images or incorrect paths
Solution:
- Only use local images from your site
- Ensure image paths are correct
- Check image permissions
Memory Errors
Cause: Large PDFs with many images
Solution:
- Increase PHP memory limit
- Reduce image DPI in settings
- Optimize images before upload
Variables Not Working
Cause: Variables not properly configured
Solution:
- Use exact variable names:
{PAGENO},{nbpg},{DATE},{sitename} - Check header/footer is enabled in settings
- Variables only work in header/footer, not in HTML content
Permission Errors
Cause: Cache directory not writable
Solution:
chmod -R 775 /site/assets/cache/WirePDF/
Excessive Logging
Problem: Too many log entries
Solution:
- Disable logging in module settings when not needed
- Use ProcessWire log pruning: Setup > Logs > Options
- ProcessWire automatically manages log rotation
Advanced Customization
Custom PDF Generator
Create your own generator template for specific needs:
<?php namespace ProcessWire;
// Custom logic
$pageId = $input->get->int('id');
$page = $pages->get($pageId);
// Build custom HTML
$html = '<h1>' . $page->title . '</h1>';
$html .= '<p>' . $page->body . '</p>';
// Generate with custom settings
$page->toPdf([
'html' => $html,
'filename' => 'custom-' . $page->name . '.pdf',
'paper_size' => 'A4',
'watermark' => 'CONFIDENTIAL',
'enable_protection' => true,
'user_password' => 'secret123'
]);Hook into Generation
// In site/ready.php
$wire->addHookBefore('WirePDF::generatePdf', function($event) {
$page = $event->arguments(0);
// Custom logic before PDF generation
});Log Files
Access logs through ProcessWire admin:
- Location: Setup > Logs > wirepdf
- Content: PDF generation process details, errors, warnings, execution times
- Features:
- Automatic timestamping by ProcessWire
- Built-in log viewer with filtering
- Automatic log rotation and pruning
- Download logs as text files
- Management: Use ProcessWire's log settings to control retention and size
Performance Tips
- Optimize Images: Compress images before upload
- Reduce DPI: Use 96 DPI for web, 150 DPI for print
- Simple CSS: Avoid complex CSS that mPDF can't parse
- Cache PDFs: Generate once, serve multiple times
- Pagination: Break large documents into smaller PDFs
- Disable Logging: Turn off logging in production for better performance
Security Notes
- PDF generator should be protected with ProcessWire permissions
- Use password protection for sensitive documents
- External images are automatically blocked
- Validate user input in custom generators
- Review logs for suspicious activity
Browser Support
PDFs can be displayed inline or downloaded in all modern browsers:
- Chrome, Firefox, Safari, Edge
- Mobile browsers (iOS Safari, Chrome Mobile)
License
MIT License - free to use in commercial and non-commercial projects
Credits
- Author: Maxim Alex — maxim@smnv.org — smnv.org
- mPDF: https://mpdf.github.io/
- ProcessWire: https://processwire.com/
Made with love for ProcessWire
More modules by Maxim Semenov
LQRS URL Shortener Profile
This site profile for ProcessWire offers a free and easy-to-use URL shortener that transforms long links into concise, shareable URLs. It is built using standard ProcessWire modules and field types.3Added 1 year ago by Maxim SemenovMedia Platform Profile
This site profile for ProcessWire offers a fully-featured media platform for hosting and managing video content with Backblaze B2 and Cloudflare integration.3Added 2 months ago by Maxim SemenovInvite Access
Restricts site access to visitors with a valid invite code. Designed for staging environments with multiple teams.1Added 4 days ago by Maxim Semenov- Added 7 days ago by Maxim Semenov
Install and use modules at your own risk. Always have a site and database backup before installing new modules.