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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?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
very good
thanks shadab