How to Convert HTML content to PDF
How to Convert HTML to PDF
Hello here we are going to show hpw easily you can convert
html content to pdf file.First of all download the library of htm2pdf and
include in your page.
HTML2pdf library has function call writeHTML which is use to
print the html content in pdf.
Let’s start
- Step 1
Download the html2pdf library
- Step 1
Create a new folder in your server and paste the html2pdf
library into it
- Step 2
Create a new file and save that file as index.php
- Step 3
Now Start coding
Include html2pdf library in index.php file
Like this
require_once(dirname(__FILE__).'/htm2pdf/html2pdf.class.php');
Now we are going to create a page for PDF
$html2pdf = new HTML2PDF('P', 'A4', 'fr');
It will create a new PDF page
Now create HTML table
I am using html tag in php code.
I am storing html table in PHP variable
<?php
$tabble = '<body style="border:2px solid
black"><table border-top=1><tr><td><img
src=pdf/logo.png></td><td
style="width:90px;"></td><td><h1>Voucher</h1></td><td
style="width:170px;"></td><td><img
width=130px;height=60px;
src="pdf/barcode.png"></td></tr></table>’;
?>
I am going to create a PDF which has HTML table, so we need
to write HTML table in PDF
$html2pdf->writeHTML($table);
Now we are going to save that pdf
Create a new folder
in your directory save as pdf in this folder our PDF will save
$filename = 'pdf/Demo.pdf';
$html2pdf->Output($filename,'F');
Run your index.php and your Pdf will generate.and save in
pdf folder
Complete Code
require_once(dirname(__FILE__).'/htm2pdf/html2pdf.class.php');
$html2pdf = new
HTML2PDF('P', 'A4', 'fr');
$html2pdf->writeHTML('<body style="border:2px solid
black"><table border-top=1><tr><td><img
src=pdf/logo.png></td><td
style="width:90px;"></td><td><h1>Voucher</h1></td><td
style="width:170px;"></td><td><img
width=130px;height=60px;
src="pdf/barcode.png"></td></tr></table>
$filename = 'pdf/Demo.pdf';
$html2pdf->Output($filename,'F');
Out Will be look like
Comments
Post a Comment