如何将 DOMPDF 生成的内容保存到文件中? [英] how to save DOMPDF generated content to file?

查看:33
本文介绍了如何将 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 生成的内容保存到文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆