本文介绍了如何将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);
这里唯一的区别是包括了include目录中的所有文件.
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生成的内容保存到文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!