how to convert html to pdf in php using fpdf To convert a PDF from HTML we use open source fpdf library.
This class allows to convert HTML to PDF. It was designed to export my blog entries to PDFs.
Also Available Main fpdf features are:
- provides for underlined, bold, italics text
- provides for headlines <h1>, <h2>, <h3> & <h4>
- provides for images
- simple provides for tables
- full provides for lists <li>
- full provides for <blockquote>
- provides for pseudo-tags <red> & <blue>
- <pre> will be shown using Courier font, other text with Times
- provides for <br>, <br /> & <p>
- provides for <hr> & <hr />
- document header is created with publishing date, article title, URL, company
- document footer is created with current & total pagination numbers
- built-in provides for iconv (character conversions)
Step 1: how to convert html to pdf in php using fpdf?
First of all you can free download FPDF Library from official main website http://www.fpdf.org/
and then this downloaded unzip file & copy as well as paste FPDF library in your main PHP project library folder.
Call fpdf.php main class where you want apply the PDF download feature, If you want to make a PDF directly with HTML then display as below official great basic and simple example.
require('lib/fpdf/fpdf.php'); $pdf = new FPDF(); $pdf->AddPage(); $pdf->SetFont('Arial','B',16); $pdf->Cell(40,10,'Welcome To Pakainfo!'); $pdf->Output();
Also second example to generate table format in pdf data content example for “how to convert html to pdf in php using fpdf”
require('lib/fpdf/fpdf.php'); class PDF extends FPDF { // Simple table function BasicTable($header, $data) { // Header foreach($header as $col) $this->Cell(40,7,$col,1); $this->Ln(); // Data foreach($data as $row) { foreach($row as $col) $this->Cell(40,6,$col,1); $this->Ln(); } } }
Now You can call BasicTable() methods where you want to generate dynamic product table in PDF format.
$pdf = new PDF(); $header = array('ID', 'Product Name', 'Price (Rs)'); $data = array( array('1', 'Mobile', '5000'), array('2', 'Laptop', '1200'), array('3', 'Computer', '1800'), ); $pdf->SetFont('Arial','',14); $pdf->AddPage(); $pdf->BasicTable($header,$data); $pdf->Output();

php convert html to pdf
Source Code
bellow a form where the user can html input some Form and convert it to PDF:
run(); } ?>HTML2PDF - www.pakainfo.com HTML2PDF
How to Convert HTML to PDF Document in PHP using fpdf?
HTML form to submit the data