1

我有两个文件位于localhost/invoicenamedx.phptemplate.php中,然后我有一个这样的 URL:

localhost/invoice/template.php?name=wawan

如何将输出页面转换为 PDF?我想要的是访问x.php然后获取转换后的template.php. 我尝试使用 mpdf,但它不起作用。

这是x.php

<?php
include("MPDF54/mpdf.php");

$mpdf=new mPDF('c','A4','','' , 0 , 0 , 0 , 0 , 0 , 0); 

$mpdf->SetDisplayMode('fullpage');

$mpdf->list_indent_first_level = 0; // 1 or 0 - whether to indent the first level of a list

$mpdf->WriteHTML(file_get_contents('template.php?name=wawan'));

$mpdf->Output();
?>

这是template.php

<div> The name is :
<?php


echo $_GET[name];

?>
4

1 回答 1

1

您可以使用输出缓冲

# Capture the output of the page:
ob_start();

$_GET['name'] = 'wawan';

require 'template.php';

$content = ob_get_contents();

ob_end_clean();

# Write the captured HTML to the PDF:
$mpdf->WriteHTML($content);
于 2012-12-12T03:44:37.857 回答