PHP HTML

HOW TO CONVERT HTML TO PDF IN PHP

Open the command line, navigate to your project folder, enter composer require mpdf/mpdf.

Composer will automatically download the latest version into the vendor/ folder.

DOWNLOAD MPDF

01

LOAD MPDF require "vendor/autoload.php"; $mpdf = new \Mpdf\Mpdf();   HTML CONTENT $html = "<h1>HELLO WORLD!</h1>"; $html .= "<p>Paragraph</p>"; $html .= "<table><tr><td>A table</td><td>Cell</td></tr></table>";

CONVERT HTML TO PDF (A)

02

CONVERT HTML TO PDF (B)

03

WRITE HTML TO PDF $mpdf->WriteHTML($html);   DIRECT OUTPUT $mpdf->Output(); OR FORCE DOWNLOAD $mpdf->Output("file.pdf", "D"); OR SAVE TO FILE ON SERVER $mpdf->Output("demo.pdf");