4

我的 php 页面有很多变量,样式表和 html 表也在那里。我知道有一些像 fpdf 这样的开源 pdf 类,但是当涉及到 php 变量以及需要从 mysql 表中提取数据时,我不知道如何将它们放在一起。我也没有pdf课的知识。我也在互联网上搜索过,找不到像我这样的新手的最佳选择。所以欢迎任何建议。

4

1 回答 1

3

您可以尝试mpdf课程。

只需下载 mpdf 类并使用以下脚本打印您的 php 页面。将以下代码另存为 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;
?>
于 2013-07-22T19:05:35.383 回答