【发布时间】:2014-10-19 03:27:03
【问题描述】:
我刚刚开始使用 mPDF。我一开始就卡住了。我正在尝试包含我的动态 php 文件并使用 mPDF 将其转换为 pdf 文件。这是我的方法:这是我将文件转换为pdf的功能
<?php
include('MPDF57/mpdf.php');
include('template1.php');
$html= "template1.php";
$mpdf=new mPDF();
$mpdf->SetDisplayMode('fullpage');
$mpdf->WriteHTML(file_get_contents($html));
$mpdf->Output('result.pdf','F');
exit;
?>
我的 template.php 文件只是一个 html 发票表布局,其中几个内容来自数据库,例如:用户地址、发票表等...我确实想从 template.php 转换 html 布局和内容文件转成pdf
但它不会将文件输出为 pdf 文件。我在这里错过了什么?
【问题讨论】:
-
是转换.php文件的来源还是.php文件生成的内容?
-
我的 template.php 文件只是一个 html 发票表格布局,其中有几个内容来自数据库,如:用户地址、发票表格等...我确实想转换 html 布局和内容将 template.php 文件转换为 pdf
-
where several content come from databas as所以,它有一个应该执行的 php 代码?file_get_contents($html)按“原样”读取文件,而不在其中运行 .php 代码。在include('template1.php');之前使用'ob_start(),在之后取缓冲区的内容,输出,如果需要,转换成pdf。 -
你可以添加代码吗?
-
ob_start(); include('template1.php'); $content = ob_get_clean(); ... your code up to .. $mpdf->WriteHTML($content);