dompdf定制问题

发布于 2024-11-16 02:39:03 字数 354 浏览 6 评论 0原文

我正在尝试优化 dompdf 来做一些有点奇怪的事情。由于它在我的服务器上,dompdf 正在从存储在服务器上某处的 php/html 文件生成一个 pdf 文件(供请求该文件的客户端使用)。这很酷,因为它不会因为 pdf 文件而使服务器陷入困境,但我遇到的问题是我希望有人能够导出一组 PDF 并以 zip 文件或类似文件的形式接收它们。

有没有办法让 dompdf 根据 php/html 文件的文件名将一组 PDF 文件导出到 zip 文件或其他文件,以便请求者可以下载它?

如果需要更多信息,请告诉我。

谢谢你!!

I'm trying to optimize dompdf to do something a bit strange. As it is on my server, dompdf is generating a pdf file (for the client requesting the file) from a php/html file stored somewhere on the server. This is cool because it doesn't bog the server down with pdf files, but the problem I have is that I want someone to be able to export a group of PDFs and receive them in a zip file or something similar.

Is there a way to make dompdf export a group of PDF files, based on the filenames of the php/html files, to a zip file or something so the person requesting it can download it?

Let me know if more information is needed.

Thank you!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尐偏执 2024-11-23 02:39:03

DOMPDF 一次仅处理一个文件。但是您可以编写一个 PHP 脚本来接受文件列表,然后使用 DOMPDF 单独解析每个文件。由于 DOMPDF 可以将渲染的 PDF 作为字符串返回,因此您可以将每个文件写入临时目录,然后在完成后存档结果。或者,如果您使用 dompdf.php,则可以使用 exec() 在类似的循环中处理每个 HTML 文档。

下面是一个简单的示例,展示了一种执行您想要的操作的方法:

$files_html = array('docs/file1.html','docs/file2.html');
foreach ($files_html as $file) {
  exec('dompdf.php ' . $file);
}
$zip = new ZipArchive();
$zip->open('docs/pdfs.zip', ZipArchive::CREATE);
$files_pdf = glob('docs/*.pdf');
foreach ($files_pdf as $file) {
  $zip->addFile($file);
}
$zip->close();
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=pdfs.zip);
header('Content-Transfer-Encoding: binary');
readfile('docs/pdfs.zip');

论坛问题跟踪器

DOMPDF only handles a single file at a time. But you could write a PHP script to accept the list of files and then use DOMPDF to parse each one separately. Since DOMPDF can return the rendered PDF as a string you could write each file out to a temporary directory then archive the results when you're done. Or, if you're using dompdf.php you could use exec() to process each HTML document in a similar loop.

Here's a simple example showing one way to do what you want:

$files_html = array('docs/file1.html','docs/file2.html');
foreach ($files_html as $file) {
  exec('dompdf.php ' . $file);
}
$zip = new ZipArchive();
$zip->open('docs/pdfs.zip', ZipArchive::CREATE);
$files_pdf = glob('docs/*.pdf');
foreach ($files_pdf as $file) {
  $zip->addFile($file);
}
$zip->close();
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=pdfs.zip);
header('Content-Transfer-Encoding: binary');
readfile('docs/pdfs.zip');

There are some discussions of using DOMPDF to batch process files in the forum and issue tracker.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文