我有一个使用mPDF的页面,当您运行该页面时,它会在浏览器中显示PDF,也可以从这里将其另存为PDF没问题。我想发生的是页面运行并生成PDF时,该页面已另存为PDF在服务器上。

这是当前代码:

<?php
include $_SERVER['DOCUMENT_ROOT'].'/include/seo-check/lib/WSAclient.php';
include $_SERVER['DOCUMENT_ROOT'].'/include/seo-check/lib/WSAParser.php';

$reportID= $_GET['reportid'];

$WSAclient = new WSAclient(WSA_USER_ID,WSA_API_KEY);

$result=$WSAclient->viewReport($reportID,WSA_SUBSCRIPTION_ID,'xml','EN');

unset($WSAclient);

ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PDF Report</title>
<!--Add your CSS here-->
</head>
<body>
<?php
echo WSAParser::viewReportResponse($result);
?>
</body>
</html>
<?php
$HTMLoutput = ob_get_contents();
ob_end_clean();


//Convert HTML 2 PDF by using MPDF PHP library
include $_SERVER['DOCUMENT_ROOT'].'/include/seo-check/lib/MPDF/mpdf.php';
$mpdf=new mPDF();

$mpdf->WriteHTML($HTMLoutput);
$mpdf->Output();
?>

就像我说的那样,这可以很好地输出PDF,但是有人可以告诉我如何另存为PDF吗?

最佳答案

mPDF docs声明Output()的第一个参数为文件路径,第二个为保存模式-您需要将其设置为'F'

$mpdf->Output('filename.pdf','F');

关于php - PHP mPDF将文件另存为PDF,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12574193/

10-09 03:57