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
    http://stackoverflow.com/search?q=fpdf – brasofilo Jul 22 '13 at 18:50
  • @brasofilo I will do it... – Lalhriatpuii Mapuii Jul 22 '13 at 18:51
  • @brasofilo I have gone through few of them and think that I need to learn fpdf class. But I sometimes think that there might the easy way out. Fpdf class is a little bit complex for newbie like us. – Lalhriatpuii Mapuii Jul 22 '13 at 18:54
  • @LalhriatpuiiMapuii: search on SO with `[php] html to pdf` yielded this very interesting thread: http://stackoverflow.com/questions/391005/convert-html-css-to-pdf-with-php – michi Jul 22 '13 at 18:57
  • http://stackoverflow.com/questions/4365698/create-pdf-pages-in-php Comvert HTML to PDF with PHP two methods in the top answer – Anigel Jul 22 '13 at 18:59
  • 1
    First, try something for yourself and ask later. Recommendation questions are off-topic. Myself, almost never have to ask, there's lots of good resources here at [so]. – brasofilo Jul 22 '13 at 18:59

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,605
  • 1
  • 25
  • 46