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.

A blogger

I am passionate blogger cum B.Tech. Computer engineering graduate. I love writing blog post. I spend my free time in writing blog post that will useful to everyone (including me). I have had some success making money blogging and want to help others do the same. I just figured that by creating a great and free resource a lot of links would follow – and they have. Some people ask me how they can repay me – which is not necessary - but for those wanting to show their appreciation, I just say linking to the article from their blog is the best compensation I could receive. Thanks for reading!

0 comments:

Post a Comment

Thanks for commenting. I will Reply you soon

 

Copyright @ 2013 PHP WORDPRESS MAGENTO .

Designed by Kcon Technosoft