how to save DOMPDF generated content to file?(如何将 DOMPDF 生成的内容保存到文件中?)
本文介绍了如何将 DOMPDF 生成的内容保存到文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Dompdf 创建 PDF 文件,但我不知道为什么它没有将创建的 PDF 保存到服务器.
I am using Dompdf to create PDF file but I don't know why it doesn't save the created PDF to server.
有什么想法吗?
require_once("./pdf/dompdf_config.inc.php");
$html =
'<html><body>'.
'<p>Put your html here, or generate it with your favourite '.
'templating system.</p>'.
'</body></html>';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
file_put_contents('Brochure.pdf', $dompdf->output());
推荐答案
我刚用过 dompdf,代码有点不一样,但是能用.
I have just used dompdf and the code was a little different but it worked.
这里是:
require_once("./pdf/dompdf_config.inc.php");
$files = glob("./pdf/include/*.php");
foreach($files as $file) include_once($file);
$html =
'<html><body>'.
'<p>Put your html here, or generate it with your favourite '.
'templating system.</p>'.
'</body></html>';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$output = $dompdf->output();
file_put_contents('Brochure.pdf', $output);
这里唯一的区别是包含目录中的所有文件.
Only difference here is that all of the files in the include directory are included.
除此之外,我唯一的建议是指定用于写入文件的完整目录路径,而不仅仅是文件名.
Other than that my only suggestion would be to specify a full directory path for writing the file rather than just the filename.
这篇关于如何将 DOMPDF 生成的内容保存到文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:如何将 DOMPDF 生成的内容保存到文件中?
猜你喜欢
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- Laravel 仓库 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01