Use the URL to PDF Converter when you want the file without installing anything. The steps below are the detail.
mPDF converts HTML to PDF in PHP. It is not Dompdf, and it is not a browser. You write markup with WriteHTML, and mPDF lays that markup out with its own engine. The same document can mix PHP calls and a few custom HTML tags. Install it with Composer and save the file on the server.
Install mPDF
composer require mpdf/mpdf
Require the Composer autoloader, then construct \Mpdf\Mpdf. The constructor takes an array. mode utf-8 is the usual choice for text outside Windows ANSI. format A4 is portrait. A4-L is landscape. Margins are millimeters.
Convert an HTML string
Set the header and footer before WriteHTML. The first page is opened as that call runs, and a header added later can miss it. Output with Destination::FILE writes the path you pass. Destination::INLINE is the default and sends the PDF to the browser. Destination::STRING_RETURN returns the bytes instead of saving them.
<?php
require 'vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf([
'mode' => 'utf-8',
'format' => 'A4',
'margin_left' => 12,
'margin_right' => 12,
'margin_top' => 16,
'margin_bottom' => 16,
]);
$mpdf->SetHTMLHeader('<div style="font-size: 10px; text-align: right;">October report</div>');
$mpdf->SetHTMLFooter('<div style="font-size: 10px; text-align: center;">{PAGENO} / {nbpg}</div>');
$html = <<<HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body { font-family: sans-serif; font-size: 12pt; }
h1 { font-size: 18pt; }
table { width: 100%; border-collapse: collapse; }
th, td { border: 1px solid #999; padding: 6px; }
tr { page-break-inside: avoid; }
</style>
</head>
<body>
<h1>October report</h1>
<p>Generated with mPDF.</p>
</body>
</html>
HTML;
$mpdf->WriteHTML($html);
$mpdf->Output('report.pdf', \Mpdf\Output\Destination::FILE);
{PAGENO} and {nbpg} are mPDF placeholders, not Chrome classes. The footer style has to be inline. The header and footer do not see the stylesheet from the document.
What this engine will and will not do
mPDF parses a subset of HTML and CSS, and it adds tags of its own. The manual shows both a PHP call and a custom tag for the same job, including bookmarks and named headers. A page that looks finished in Chrome is not a document mPDF can take unchanged. Build the HTML for this library: tables, simple CSS, and the page-break properties the manual lists.
If you need a stylesheet split from the body, WriteHTML accepts a mode. \Mpdf\HTMLParserMode::HEADER_CSS reads styles only. \Mpdf\HTMLParserMode::HTML_BODY reads the body. Pass the stylesheet first.
Dompdf is the other PHP path. It is also not Chrome. It does not use WriteHTML, and a Dompdf script will not run on mPDF. Browser print CSS, including the rules that keep a table row together in Chrome, is covered in print from CSS to PDF.
Skip the install
For a public URL, the URL to PDF converter uses headless Chrome in screen mode. Print-only rules are skipped, and the paper size comes from the form, not from @page. The file is deleted after download. There is no signup and no watermark.
Other stacks: HTML to PDF in Node and HTML to PDF in Python.





