简体   繁体   English

mPDF将可变的PHP页面转换为PDF

[英]mPDF converting variable PHP page into PDF

I am trying to use mPDF to convert a site into PDF. 我正在尝试使用mPDF将网站转换为PDF。

The thing is that my site is a PHP variable page, which displays information for customers depending on their username and order ID. 事实是,我的网站是一个PHP变量页面,该页面根据客户的用户名和订单ID为客户显示信息。 However, the website name is always the same: personalArea.php. 但是,网站名称始终相同:personalArea.php。

So, I would like to have a link that says Export to PDF, so the user exports his information. 因此,我希望有一个链接显示为“导出为PDF”,以便用户导出其信息。

I am planning on using file_put_contents to put the current page into a HTML file and then use the mPDF to export that HTML into PDF. 我打算使用file_put_contents将当前页面放入HTML文件,然后使用mPDF将HTML导出为PDF。 Is this a good practice? 这是一个好习惯吗? My concern is the volume, I would be creating many HTMLs... I could delete them immediately, but not sure if there is a better way to do this. 我担心的是数量,我将创建许多HTML ...我可以立即删除它们,但不确定是否有更好的方法可以做到这一点。

Thanks 谢谢

I've used mPDF before and a simple sample code could be: 我以前使用过mPDF,简单的示例代码可能是:

$yourHtml = "ABCD.html";
$mpdf=new mPDF();
$stylesheet = file_get_contents('design.css'); //if you wanted some styling
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML(file_get_contents($yourHtml)); 
unlink($yourHtml); //You could delet your file after showing it if it is just on the fly
$mpdf->Output();
exit;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM