4

My php page has a lot of variables and style sheet and html tables are also there. I know that there are some opensource pdf class like fpdf, but when it comes to php variables and when I need to pull data from mysql table, I have no idea how to put them together. I have no knowledge in pdf class also. I have also search in internet and could not find what could be the best option to start with for a newbie like me. So any suggestion is welcome.

1 Answers1

3

You can try mpdf class.

Just download mpdf class and use the following script to print your php page. Save the below code as mypdfgenerator.php.:

<?php 
include("mpdf.php");
$mpdf=new mPDF('win-1252','A4','','',15,10,16,10,10,10);//A4 page in portrait for landscape add -L.
$mpdf->SetHeader('|Your Header here|');
$mpdf->setFooter('{PAGENO}');// Giving page number to your footer.
$mpdf->useOnlyCoreFonts = true;    // false is default
$mpdf->SetDisplayMode('fullpage');
// Buffer the following html with PHP so we can store it to a variable later
ob_start();
?>
<?php include "phppage.php";
 //This is your php page ?>
<?php 
$html = ob_get_contents();
ob_end_clean();
// send the captured HTML from the output buffer to the mPDF class for processing
$mpdf->WriteHTML($html);
//$mpdf->SetProtection(array(), 'user', 'password'); uncomment to protect your pdf page with password.
$mpdf->Output();
exit;
?>
Mawia HL
  • 3,375
  • 1
  • 22
  • 45