PHP mPDF save file as PDF(PHP mPDF 将文件保存为 PDF)
问题描述
我有一个使用 mPDF 的页面,当您运行时在浏览器中显示一个 PDF,它也可以从这里保存为 PDF 没问题.我想要发生的是当页面运行并生成一个 PDF 时,该页面在服务器上保存为 PDF.
I have a page which uses mPDF which when you run displays a PDF in the browser, it can also be saved from here as a PDF no problem. What I would like to happen is when the page is run and generates a PDF that the page is saved as a PDF on the server.
这是当前代码:
<?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 吗?
Like I said this outputs the PDF fine but could someone tell me how to save as a PDF?
推荐答案
mPDFdocs 声明 Output()
的第一个参数是文件路径,第二个是保存模式 - 您需要将其设置为 'F'
.
The mPDF docs state that the first argument of Output()
is the file path, second is the saving mode - you need to set it to 'F'
.
$mpdf->Output('filename.pdf','F');
这篇关于PHP mPDF 将文件保存为 PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP mPDF 将文件保存为 PDF
基础教程推荐
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01