How to generate PDF files of your web page using TCPDF

There are a number of options available if you are searching for an open source library to generate PDF files however the best option is TCPDF. It offers a lot of support in generating PDF files directly from HTML. You can even generate PDF files in custom fonts. Check out the following example which will generate and download PDF file from the HTML input passed to it.

$strFile = ;

require("tcpdf/tcpdf.php");   
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);				  
$pdf->SetFont('helvetica', '', 10);
$pdf->AddPage();
$pdf->writeHTML($strFile, true, 0, true, 0);
$strFileName = 'my_pdf_file.pdf';
$pdf->Output($strFileName, 'D');   	  
$pdf = null;
Please follow and like us:

Be the first to comment

Leave a Reply

Your email address will not be published.


*