Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesSome links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
PHP does not turn arbitrary HTML into a PDF by itself. You need a renderer such as Dompdf, mPDF, TCPDF/tc-lib-pdf, or a browser service. For a conventional table, Dompdf is the shortest path; mPDF is strong for UTF-8, headers, footers, and print reports; TCPDF gives explicit page-flow control; and headless Chrome is the best fit when the PDF must match modern browser CSS.
Choose a renderer before writing the export
Your choice determines which HTML and CSS will work, how rows paginate, and how much deployment work is required.
| Renderer | Best fit | Important constraints |
|---|---|---|
| Dompdf | Conventional tables and mostly CSS 2.1 layouts | Rows cannot split across pages; flexbox and Grid are unsupported; malformed HTML can cause rendering problems. |
| mPDF | UTF-8 reports with headers, footers, page numbers, and print styling | Untrusted HTML/CSS requires strong vetting; modern CSS fidelity is below a browser renderer. |
| TCPDF/tc-lib-pdf | Explicit PHP control, structured tables, and page-flow behavior | HTML/CSS is a supported subset rendered by the library, so unsupported CSS must be checked. |
| Headless Chrome | Existing pages or modern CSS that must resemble browser output | Requires a browser process or service and additional operational deployment work. |
Use semantic <thead>, <tbody>, and <tfoot> elements regardless of library. They make the document clearer and allow renderers that support repeated headers to identify them.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteExport a table with Dompdf
Install it
From your project directory, install the package with Composer:
#1 Best Overall
composer require dompdf/dompdf
Complete runnable example
This endpoint builds a UTF-8 document, escapes every dynamic value, renders A4 portrait output, and streams it inline in the browser.
<?php
require __DIR__ . '/vendor/autoload.php';
use DompdfDompdf;
use DompdfOptions;
$options = new Options();
$options->set('isHtml5ParserEnabled', true);
$dompdf = new Dompdf($options);
$rows = [
['name' => 'Ada', 'total' => '42.00'],
['name' => 'Grace', 'total' => '37.50'],
['name' => '李明', 'total' => '19.95'],
];
$html = '<!doctype html><html><head><meta charset="utf-8"><style>
@page { margin: 18mm; }
body { font-family: DejaVu Sans, sans-serif; font-size: 10pt; }
table { width: 100%; border-collapse: collapse; }
th, td { border: 1px solid #999; padding: 6px; text-align: left; }
th { background: #eee; }
</style></head><body><table><thead><tr><th>Name</th><th>Total</th></tr></thead><tbody>';
foreach ($rows as $row) {
$name = htmlspecialchars($row['name'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
$total = htmlspecialchars($row['total'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
$html .= '<tr><td>' . $name . '</td><td>' . $total . '</td></tr>';
}
$html .= '</tbody></table></body></html>';
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream('table.pdf', ['Attachment' => false]);
Dompdf’s project documentation lists HTML5 parsing, HTML/CSS rendering, complex tables, and controls for remote resources and local-file chroot paths. Remote images or stylesheets require remote access to be enabled and a suitable PHP HTTP capability. Local files must be inside an allowed chroot. DejaVu TrueType fonts are included for useful Unicode coverage.
Pagination limitations
Dompdf documents that table cells are not pageable: a table row must fit on one page. Keep descriptions reasonably short, reduce padding or font size, and split very large records into separate rows or tables. Do not expect flexbox or CSS Grid layouts to behave like a browser.
Recommended Free Tools
Use mPDF for UTF-8 reports and print features
Install and render
composer require mpdf/mpdf
<?php
require __DIR__ . '/vendor/autoload.php';
$mpdf = new MpdfMpdf([
'format' => 'A4',
'margin_left' => 18,
'margin_right' => 18,
'margin_top' => 18,
'margin_bottom' => 18,
]);
$html = '<!doctype html><meta charset="utf-8">' . $tableHtml;
$mpdf->WriteHTML($html);
$mpdf->Output('table.pdf', MpdfOutputDestination::INLINE);
mPDF is designed around UTF-8 HTML and is convenient for headers, footers, and page numbers. Treat the HTML passed to WriteHTML() as trusted, escaped template output. Its manual warns that outside HTML/CSS needs stronger vetting and sanitization than ordinary browser input. If you need state-of-the-art CSS or close page mirroring, use a browser renderer instead.
Rank #2
Make dynamic cells safe
Escape text before inserting it into $tableHtml:
$safe = htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
Never concatenate untrusted user markup into the document. If users can supply rich content, sanitize it with a policy appropriate to your application, or render only a server-controlled template.
Use TCPDF or tc-lib-pdf when page flow must be explicit
TCPDF’s HTML API and the current tc-lib-pdf path expose addHTMLCell() for placing an HTML block while accounting for automatic page and region breaks. The documented table support includes thead, tbody, tfoot, row and column spans, both border models, and repeated headers when a table crosses pages. This is useful for long invoices and reports where page-flow behavior matters more than unrestricted CSS.
Because the library renders a supported HTML/CSS subset rather than running a browser, verify every style you depend on. Start with simple widths, borders, padding, and semantic sections; avoid assuming Bootstrap or arbitrary third-party CSS will work unchanged.
Free tools Windows power users keep installed
One-click scans. No signup required.
Build HTML that survives PDF pagination
Use stable table structure
- Put column labels in
<thead>, data in<tbody>, and totals in<tfoot>. - Set an explicit width such as
width:100%and use fixed or percentage column widths for wide data. - Use modest padding and readable font sizes.
- Keep a single record’s text short when using Dompdf, because its rows cannot split.
Handle wide tables
Switch to landscape paper, reduce margins, or select only essential columns. A browser viewport’s responsive layout is not automatically reproduced by a PHP PDF library. If the source page relies on media queries, test the print stylesheet separately.
Repeat headers and control breaks
Semantic headers are required for reliable repetition, but support differs by renderer. TCPDF documents repeated thead rows across pages. With Dompdf, design rows that fit and test the exact data volume. Add page-break rules only where the chosen renderer supports them.
Images, fonts, and non-ASCII text
Declare <meta charset="utf-8"> and keep PHP source, database strings, and templates in UTF-8. Choose a font that contains the scripts you actually output; DejaVu fonts bundled with Dompdf cover many common Unicode characters, but they are not a guarantee for every writing system. For logos and images, use permitted local paths or enable and secure remote access according to the renderer’s resource rules. Test missing images, transparent PNGs, and large files before production.
Security and operational checklist
- Escape every dynamic cell with
htmlspecialchars()usingENT_QUOTES | ENT_SUBSTITUTEand UTF-8. - Do not pass user-controlled HTML/CSS directly to mPDF or any renderer.
- Restrict Dompdf’s chroot to the directories that really contain templates and assets.
- Enable remote resources only when needed, and control which URLs can be fetched.
- Set execution and memory limits appropriate to your largest report; profile with your own data rather than relying on an assumed benchmark.
- Stream with
Content-Type: application/pdfor save to controlled storage. Avoid printing warnings or debug output before PDF bytes.
Testing plan for a production table PDF
- Test an empty dataset and confirm the headers and an intentional “no rows” message render correctly.
- Test one row, enough rows to cross a page, and a row with a long description.
- Test very wide columns, long unbroken strings, null values, quotes, ampersands, and HTML-looking text.
- Test accented characters, emoji where supported, and every script your users submit.
- Test images that load, images that are missing, and restricted remote resources.
- Open the result in more than one PDF viewer and verify page count, totals, links, and download headers.
Common failures and fixes
“Class not found” or missing autoloader
Run the Composer command in the deployed project and include the matching vendor/autoload.php path. Deploy the vendor directory or run Composer as part of deployment.
Blank or corrupt PDF
Check for PHP notices, whitespace, or debug output before the PDF stream. Capture renderer exceptions in logs, and confirm the generated HTML is valid and contains a closing document structure.
Rank #4
Rows disappear or are cut off
For Dompdf, the row is probably too tall to fit on a page. Shorten the cell, reduce spacing, or split the content. Do not expect a row to break across pages.
Header is not repeated
Use a real thead rather than a styled first body row, then verify that your selected renderer supports repeated headers. TCPDF’s documented HTML table API does; behavior is not universal.
CSS or Bootstrap styling is missing
PDF libraries implement subsets of CSS. Replace layout-heavy rules with explicit table widths, borders, padding, and print-specific styles. Choose headless Chrome when browser-level CSS fidelity is a requirement.
Images or fonts do not load
Confirm the path is allowed, remote access is intentionally enabled if required, and the font contains the characters. Use absolute, controlled asset paths and inspect renderer logs.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
If your goal is to capture an existing web table rather than generate a server-side report, ScreenshotNeo provides a website screenshot API and MCP server. One GET request returns PNG, JPEG, WebP, or PDF. It accepts cookie banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status.
For a PDF capture, call the API with the target URL and PDF options described in the ScreenshotNeo documentation:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
The same endpoint can be called from PHP:
<?php
$url = 'https://api.screenshotneo.com/v1/shot';
$query = http_build_query([
'access_key' => 'YOUR_API_KEY',
'url' => 'https://stripe.com',
]);
$context = stream_context_create(['http' => ['timeout' => 90]]);
$data = file_get_contents($url . '?' . $query, false, $context);
if ($data === false) {
throw new RuntimeException('Screenshot request failed');
}
file_put_contents(__DIR__ . '/shot.webp', $data);
ScreenshotNeo also supports element capture by CSS selector, full-page lazy-image loading, custom CSS and JavaScript, clicks, selector or network-idle waits, headers, cookies, user agents, authorization, timezone and geolocation, blocking rules, resizing, chosen cache TTLs, signed image links, asynchronous webhooks, bulk capture of up to 100 URLs per call, usage reporting, and an OpenAPI specification. Its MCP tools—take_screenshot, get_page_info, and capture_pdf—let Claude, Cursor, or another MCP client perform captures.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
There is a free allowance of 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is included on every plan. Create a free ScreenshotNeo account to try it.
Which approach should you use?
- Dompdf: choose it for a controlled, simple table and the smallest implementation.
- mPDF: choose it for UTF-8 print reports with headers, footers, and page numbers.
- TCPDF/tc-lib-pdf: choose it when structured table pagination and explicit PDF control are central.
- Headless Chrome: choose it when modern CSS or pixel similarity to a web page outweighs deployment simplicity.
- ScreenshotNeo: choose it when you need a hosted capture of an existing URL, cleanup of consent UI, or AI-agent and bulk-capture workflows without operating a browser.
Frequently Asked Questions
Can PHP convert an HTML table to PDF without a library?
No. PHP needs a PDF renderer or a browser-based service to interpret HTML and produce PDF bytes.
Why does my table look different from the browser?
Dompdf, mPDF, and TCPDF implement their own HTML/CSS subsets. Browser rendering is the appropriate choice when exact modern CSS fidelity is required.
How should I export a table with untrusted user content?
Render a server-controlled template, escape text values, sanitize any permitted rich content, and apply the renderer’s resource restrictions.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

