Jump to content

Recommended Posts

Posted

Hi all,

I'd like to introduce LePdf, a small ProcessWire module that wraps mPDF: you give it HTML, it gives you a PDF. You can show it in the browser, send it as a download, save it to disk, or get it as a string. The mPDF instance stays directly accessible, so nothing is hidden from you.

Why another PDF module?
I use RockPdf in a few projects, and its development has been discontinued. I wanted something small that I can maintain myself, runs on plain shared hosting, and covers what I actually need: output, download, save. LePdf is an independent implementation. The basic idea (a thin wrapper around mPDF) is inspired by RockPdf. I contacted @bernhard beforehand, and he replied that he has no problem with it and is happy about it. ❤️

LePdf is not a drop-in replacement. There is no backwards compatibility with the RockPdf API.

Features

  • write(), css(), renderTemplate(), show(), download(), save(), output()
  • Header, footer, title, author (set globally in the module config or per document)
  • Custom fonts and icon fonts (e.g. FontAwesome)
  • Direct access to the mPDF instance via $pdf->mpdf
  • mPDF is bundled, so no Composer is needed (useful on shared hosting)
  • Module configuration page with an explanation and example for every field
  • Config page translatable with ProcessWire's language system; CSV files for DE, FR, ES, PT, IT, NL are included


Quick start

$pdf = $modules->get('LePdf');          // every get() returns a new, empty PDF
$pdf->write('<h1>Hello</h1><p>This is a PDF.</p>');
$pdf->show('hello.pdf');                // show in the browser and end the script


Example: attendance list with a signature column

<?php namespace ProcessWire;

// check access before anything is generated
if(!$user->isLoggedin() || !$user->hasRole('editor')) throw new Wire404Exception();

$event = $pages->get((int) $input->get->id);

$rows = '';
foreach($event->participants->sort('name') as $u) {
	$rows .= '<tr><td>' . $sanitizer->entities($u->name) . '</td><td></td><td></td></tr>';
}

$pdf = $modules->get('LePdf');
$pdf->title("Attendance {$event->title}");
$pdf->css('td, th { border: 1px solid #000; padding: 4mm; } th { background: #eee; }');
$pdf->write('<h2>' . $sanitizer->entities($event->title) . "</h2>
<table width='100%' style='border-collapse: collapse'>
<tr><th>Name</th><th width='15%'>Present</th><th width='35%'>Signature</th></tr>
$rows
</table>");
$pdf->show('attendance.pdf');

 

The admin configuration page

LePdf_config.thumb.png.bf4d8778fa35cf54af0c9b8305a04148.png

 

Requirements

  • PHP 7.4 or newer (bundled mPDF 8.3 supports up to PHP 8.5)
  • ProcessWire 3.0 or newer
  • PHP extensions mbstring and gd; zlib recommended

Installation
Copy the folder to site/modules/LePdf/, then Modules > Refresh > install LePdf. Details are in the README.

Status
Version 0.1.0, early. I tested it manually on PHP 8.5 on shared hosting; the automated tests (which run without ProcessWire) run on PHP 8.3. Real-world testing on other setups is exactly what I'm missing.

Notes

  • LePdf does not check permissions and does not escape HTML. Access control and escaping belong in your template (see the README).
  • The translations were created with AI assistance and have not been reviewed by native speakers. Corrections are welcome.

 

Feedback
I'd be glad about bug reports, test results on other hosting setups, corrections to the translations, and ideas for what should come next. I'm deliberately keeping version 1 small.

 

License
LePdf is MIT. The bundled mPDF is GPL-2.0-only (see lib/THIRD-PARTY.md in the repo).

GitHub repository

  • Like 5

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...