html to pdf

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

We 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.

 $pdf=new HTML2FPDF();
 $fp = fopen("sample.html","r");
 $strContent = fread($fp, filesize("sample.html"));
 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.


One thought on “HTML to PDF

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s