【问题标题】:How can I export my php page to PDF using php? [closed]如何使用 php 将我的 php 页面导出为 PDF? [关闭]
【发布时间】:2013-07-21 15:12:20
【问题描述】:

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

【问题讨论】:

  • @brasofilo 我会做的...
  • @brasofilo 我经历了其中的几个,并认为我需要学习 fpdf 类。但我有时认为可能有简单的出路。 Fpdf 类对于我们这样的新手来说有点复杂。
  • @LalhriatpuiiMapuii:在 SO 上搜索 [php] html to pdf 产生了这个非常有趣的线程:stackoverflow.com/questions/391005/…
  • 首先,自己尝试一下,稍后再询问。推荐问题是题外话。我自己,几乎不用问,Stack Overflow 有很多很好的资源。

标签: php pdf


【解决方案1】:

你可以试试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;
?>

【讨论】:

  • 我会测试你的代码。首先让我下载课程。
  • @LalhriatpuiiMapuii 如果您打算将其用于离线目的或不在站点中动态打印的内容,您可以选择 [Universal Document Converter](www.print-driver.com/‎) .
  • 使用这个 MPDF 类是多么容易,它也有很好的文档。谢谢你。我想这就是我要找的。​​span>
猜你喜欢
  • 2013-04-09
  • 2016-09-09
  • 1970-01-01
  • 2013-08-09
  • 1970-01-01
  • 2017-12-22
  • 1970-01-01
  • 2011-07-17
  • 1970-01-01
相关资源
最近更新 更多