gpt4 book ai didi

php - 如何将 DOMPDF 生成的内容保存到文件中?

转载 作者:IT王子 更新时间:2023-10-29 00:49:28 26 4
gpt4 key购买 nike

我正在使用 Dompdf 创建 PDF 文件,但我不知道为什么它没有将创建的 PDF 保存到服务器。

有什么想法吗?

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,代码有点不同,但它可以工作。

这里是:

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);

这里唯一的区别是包含目录中的所有文件。

除此之外,我唯一的建议是指定用于写入文件的完整目录路径,而不仅仅是文件名。

关于php - 如何将 DOMPDF 生成的内容保存到文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8720897/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com