Free PHP & Laravel Dompdf Templates & Code Generator
Pure-PHP HTML-to-PDF engine for Laravel, Symfony, and WordPress with zero Node.js or Chromium sidecars. Emits compact PDFs (2.2 KB in 17 ms single-page; 140.7 KB across 22 stress-test pages in 1.03s), though CSS Flexbox/Grid support remains partial.
Install: composer require dompdf/dompdf:^3.1.0 | Runtime: PHP (PHP 8+) | Version: 3.1.0 | Popularity: 3.2M/mo installs
Works with: Laravel (barryvdh/laravel-dompdf), Symfony, WordPress, CodeIgniter, PHP 8
How Dompdf (PHP / Laravel) Templates Work in CodePDF
Emits a standalone PHP 8 script configuring Dompdf\Options (isRemoteEnabled, defaultFont) and rendering Dompdf-safe positioned/tabular HTML + CSS into a crisp PDF.
- Eliminates Dompdf's infamous CSS Flexbox/Grid layout breakage with deterministic Dompdf-tested CSS
- Fast ~292ms PHP execution via Composer with zero Node.js or headless Chrome sidecars
- Drops cleanly into Laravel controllers, Symfony services, WooCommerce/WordPress plugins, or CLI scripts
Quick Start: Generate PDFs with Dompdf
Install Dompdf (PHP / Laravel) (PHP 8+), then run the code CodePDF exports for any template:
composer require dompdf/dompdf:^3.1.0
- Run composer require dompdf/dompdf:^3.1.0 in your project root.
- Save the generated file as generatePdf.php.
- Run php generatePdf.php to produce the PDF.
- Set isRemoteEnabled to true only when loading remote images (disabled by default for security).
- For large documents consider increasing PHP memory_limit in php.ini.
Example Dompdf Output (Standard B2B Commercial Invoice)
Compiled directly from the Standard B2B Commercial Invoice template (PHP 8+):
<?php
require_once __DIR__ . '/vendor/autoload.php';
// Dompdf: composer require dompdf/dompdf (LGPL-2.1; transitive deps include LGPL-3.0)
use Dompdf\Dompdf;
use Dompdf\Options;
// This code is generated using codepdf.dev
if (!function_exists('_codepdf_wrap_text_est')) {
function _codepdf_est_width(string $s, float $fontSize, bool $mono = false, bool $bold = false): float
{
$len = function_exists('mb_strlen') ? mb_strlen($s, 'UTF-8') : strlen($s);
if ($mono) return $len * $fontSize * 0.6;
$scale = $bold ? 1.07 : 1.0;
$w = 0.0;
for ($i = 0; $i < $len; $i++) {
$ch = function_exists('mb_substr') ? mb_substr($s, $i, 1, 'UTF-8') : $s[$i];
if ($ch === ' ') $w += 0.28;
elseif (strpos("ilI!|.,:;'\x60tfrj1", $ch) !== false) $w += 0.28;
elseif (strpos('mwMW@%', $ch) !== false) $w += 0.82;
elseif ($ch >= 'A' && $ch <= 'Z') $w += 0.66;
else $w += 0.53;
}
return $w * $fontSize * $scale;
}
function _codepdf_wrap_text_est($text, float $maxWidth, float $fontSize, bool $mono = false, bool $bold = false): array
{
$maxWidth = max(1.0, $maxWidth);
// … (445 more lines in full generated file)
Custom Fonts in Dompdf
Generated code falls back to Standard 14 fonts for inline base64 font data; load local .ttf files via CSS @font-face inside Dompdf's configured chroot and writable fontCache directories.
- Place .ttf files in a folder inside Dompdf's configured chroot directory.
- Declare @font-face with format('truetype') for each weight (400, 700).
- Enable $options->setIsRemoteEnabled(true) only if loading fonts from external HTTPS URLs.
Official documentation: Dompdf docs
Dompdf Benchmark Results
Measured on CodePDF’s 26-component, 22-page All-Components Dynamic Multi-Page Flow Stress Test (same document across all 22 libraries).
| Metric | Dompdf | Rank (of 22) |
|---|---|---|
| Wall-clock time | 1.03 s | 18th fastest |
| CPU time | 1.13 s | 16th lowest |
| Peak RAM | 103.2 MB | 11th lowest |
| PDF file size | 140.7 KB | 7th smallest |
- Engine type
- CSS-to-PDF
- Under the hood
- Pure-PHP HTML + CSS 2.1/CSS3 layout engine writing PDF streams via CPDF
- Runs in
- PHP 8+ (Laravel, Symfony, WordPress)
- Verdict
- Pure-PHP HTML/CSS for Laravel with compact output (140.7 KB across 22p in 1.03s; 17 ms / 2.2 KB single-page); partial Flexbox.
Under the Hood & Benchmark Highlights
- PHP’s most popular HTML-to-PDF engine (3.2M/mo Composer installs) — runs purely in PHP with zero Node.js or Chromium sidecars.
- Surprising standout: produced the #2 smallest PDF across all 22 libraries on our 11-page 26-component test (79.1 KB in 741 ms, 81.1 MB RAM) — nearly 6× smaller than Puppeteer.
- Gap: CSS Flexbox/Grid support is incomplete, so CodePDF outputs Dompdf-safe positioned/table CSS.
Good to Know (Dompdf Caveats)
- Incomplete CSS Flexbox & Grid: Dompdf's CSS engine is primarily CSS 2.1 with partial CSS3 — complex Flexbox/Grid layouts frequently misalign, so CodePDF emits Dompdf-tested positioning and table markup.
- Security & asset paths: Remote images/fonts are blocked unless isRemoteEnabled is true, and local font/image paths must sit inside Dompdf's configured chroot directory with a writable fontCache folder.
- Memory & dynamic barcodes: Large multi-page HTML tables can hit PHP's default memory_limit; static barcodes are embedded as PNG data URIs, while dynamic runtime barcode encoding is better handled in TCPDF or with a PHP barcode package.
Popular Dompdf PDF Templates
- Standard B2B Commercial Invoice Dompdf template — Enterprise commercial tax invoice with QR payment link, Currency balance KPIs, line-item ledger, and ACH wire instructions.
- Professional Invoice Dompdf template — Line-item invoice with billing details, totals and payment terms.
- Payment Receipt Dompdf template — Clean transaction receipt with payment method details, item breakdown and verified badge.
- Purchase Order Dompdf template — Procurement PO with vendor, ship-to, line items and approval block.
- Certificate of Completion Dompdf template — Landscape certificate with decorative border, recipient name and signatures.
- Official Landlord Rent Payment Receipt Dompdf template — Statutory rent payment receipt with QR ledger verification, itemized rent/parking allocation, and $0.00 current balance confirmation.
All 100 CodePDF templates export to Dompdf (PHP / Laravel). Browse them by category: Career (5) · Business (6) · Education (7) · Marketing (6) · Human Resources (8) · Finance (7) · Legal (8) · Healthcare (10) · Logistics (6) · Real Estate (6) · Hospitality (4) · Operations (5) · Technology (5) · Banking (9) · Non-Profit (4) · Personal (3) · Compliance & Enterprise (1), or see the full template gallery.
Dompdf Template FAQs
Can I use these Dompdf templates with barryvdh/laravel-dompdf in Laravel?
Yes! You can either call the generated PHP builder function directly in your Laravel controller/service or drop the generated HTML markup into a Blade view for Pdf::loadHTML() / Pdf::loadView().
Why don't these templates break on Dompdf's CSS limitations?
CodePDF's Dompdf compiler avoids unsupported CSS Grid/Flexbox constructs and emits explicit coordinates, tables, and @page rules verified against Dompdf 3.x.
How are QR codes and barcodes rendered in Dompdf?
Static barcodes and QR codes are embedded as inline base64 PNG data URIs so Dompdf renders them sharply without external GD/Imagick plugins; for dynamically changing runtime barcode values in PHP, use TCPDF or generate the PNG via a PHP barcode package.
Dompdf vs Other PHP PDF Libraries
- TCPDF (PHP) — 176 ms, 41 MB RAM, 195.9 KB PDF. Fast pure-PHP coordinate canvas with built-in UTF-8 & barcodes (176 ms for 22p, 2.7 ms single-page, 41.0 MB RAM); maintenance mode.
- FPDF (PHP) — 37 ms, 28.8 MB RAM, 140.1 KB PDF. #4 fastest overall & #1 fastest interpreted engine (37 ms for 22p, 0.4 ms single-page, 28.8 MB RAM); ISO-8859-1 only (no UTF-8).
See the full 22-library benchmark rankings · Compare all supported PDF libraries