Showing posts with label html to pdf. Show all posts
Showing posts with label html to pdf. Show all posts

Thursday, January 30, 2014

PHP - HTML to PDF

How to do HTML to PDF in PHP ?


In this post , I will cover as how you convert an HTML page into PDF  file on a fly.
You basically need an fpdf  library to do the task.You may download it from http://www.fpdf.org/en/download.phpWe will be using HTML2FPDF class of fpdf library.
Now let us see, how to convert a sample HTML page into a PDF file using HTML2FPDF Library.
Below is the code for the conversion.
<?php

require('html2fpdf.php');

$pdf=new HTML2FPDF();

$pdf->AddPage();

$fp = fopen("sample.html","r");

$strContent = fread($fp, filesize("sample.html"));

fclose($fp);

$pdf->WriteHTML($strContent);

$pdf->Output("sample.pdf");

echo "PDF file is generated successfully!"; 

Just that simple.You just need to include html2fpdf.php.Here I have passed sample.html page,the pdf generated will have same content of sample.html page,however in the pdf format.

 

Copyright @ 2013 PHP WORDPRESS MAGENTO .

Designed by Kcon Technosoft