Convert Html to PDF in PHP Php by Rajesh Kumar Sahanee - January 5, 2016September 13, 20172 Post Views: 6,944 Hello Friends Today I going to share how to convert Html to PDF in PHP. First of all we need PHP api to convert html to pdf, So I am going to use Html2Pdf which you can download from url given below. https://github.com/spipu/html2pdf/releases After downloading API here are the steps you need to follow:- Step 1: Extract download file Step 2: Now create your php file Step 3: Include api and convert to pdf Here is the code index.php PHP <?php require_once('html2pdf/html2pdf.class.php'); $html2pdf = new HTML2PDF('P', 'A4', 'fr'); //HTML2PDF object created $content = '<html>' . '<body>' . '<h1>Test Heading</h1>' . '<p>This is test html body</p>' . '<p style="color: blue;">This is test html body</p>' . '<p style="background-color: orange;">This is test html body</p>' . '</body>' . '</html>';//html which will be printed $html2pdf->WriteHTML($content); //processing html and perform conversion $filename = 'test.pdf'; $html2pdf->Output($filename); 123456789101112131415161718 <?php require_once('html2pdf/html2pdf.class.php'); $html2pdf = new HTML2PDF('P', 'A4', 'fr'); //HTML2PDF object created $content = '<html>' . '<body>' . '<h1>Test Heading</h1>' . '<p>This is test html body</p>' . '<p style="color: blue;">This is test html body</p>' . '<p style="background-color: orange;">This is test html body</p>' . '</body>' . '</html>';//html which will be printed $html2pdf->WriteHTML($content); //processing html and perform conversion$filename = 'test.pdf';$html2pdf->Output($filename); Output Download Code Convert Html to PDF in PHP 1 file(s) 6.56 MB Download