php - 像 Verisign/Docusign 一样非常非常快地将 PDF 转换为 PNG

标签 php pdf

我一直在使用 PDF 到 PNG 的转换,并尝试了 ImageMagick 和 Ghostscript。

我有一个 36 页的文档,该文档被拆分为多个单独的 PDF。我在一台运行 Linux 且具有 8 GB RAM 的 i7 机器上完成所有 36 页的最快转换大约需要 20 秒。

我看到 VeriSign/DocuSign,当然还有 Adob​​e EchoSign 能够在 10 秒(有时大约 5 秒)内将所有这些文件转换为“预览”。

有什么我想念的吗?真的只是关于机器本身吗?

这是我让他们使用 Ghostscript 和此命令转换的最快速度:

gs -q -dQUIET -qNODISPLAY -dNumRenderingThreads=4 -dNOPAUSE \
   -sDEVICE=jpeg -sOutputFile=$exportPathCleaned -dJPEGQ=90 \
   -r100 -q $pdf -c quit

是否无法达到他们的速度? 编辑 PHP/Java 平台是我的目标

编辑 2 以进行澄清 - 希望能够这样做以开发与 VeriSign/DocuSign 等类似的系统,以便可以将 div 和其他项目放置在输出 View 。据我所知,您无法使用直接 PDF 执行此操作,这就是为什么他们将所有内容都转换为图像。

最佳答案

我在一台使用了 4 年、内存为 4GB 的 MacBook Pro 上使用了这个命令,处理您链接的示例 PDF:

$> time gs -q -sDEVICE=jpeg -o evs-%02d.jpg -dJPEGQ=90 -r100 EVS.pdf

返回 11 个 JPEG,带有以下时间信息:

real  0m1.011s
user  0m1.063s
sys   0m0.091s

即:~1 sec 11 页。

我没有发现您的样本 PDF 有任何性能问题。但是,您的 PDF 并不完全符合 Kosher 标准,正如来自 Ghostscript 的警告消息所示:

**** Warning: can't process font stream, loading font by the name.

**** This file had errors that were repaired or ignored.
**** The file was produced by: 
**** >>>> Acrobat Distiller 9.5.5 (Windows) <<<<
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.

该文件包含 231 张图像或模板。

此外,它没有嵌入(所有)它使用的字体:

$> pdffonts Documents/pdfs/EVS.pdf

name                      type          encoding     emb sub uni object ID
------------------------- ------------- ------------ --- --- --- ---------
TimesNewRomanPSMT         TrueType      WinAnsi      no  no  no     636  0
TimesNewRomanPS-BoldMT    TrueType      WinAnsi      no  no  no     638  0
Arial-Black               TrueType      WinAnsi      no  no  no     335  0
EPBFLF+Cambria            CID TrueType  Identity-H   yes yes yes    332  0
Helvetica                 Type 1        Custom       no  no  no     511  0
ArialMT                   TrueType      WinAnsi      no  no  no     476  0
FAMLHA+Wingdings-Regular  CID TrueType  Identity-H   yes yes yes    496  0
TimesNewRomanPS-ItalicMT  TrueType      WinAnsi      no  no  no     495  0

如果嵌入这些字体,Ghostscript 就不必...

  1. ...搜索合适的替代字体,
  2. ...从硬盘加载替代字体,
  3. ...在呈现为 JPEG 输出时应用替代字体。

处理成 JPEG 的速度会更快即使嵌入字体的 PDF 会更大!

我通过将字体嵌入您的示例 PDF 并再次运行上述命令来验证我最后的断言:

$> time gs -q -sDEVICE=jpeg -o evs-%02d.jpg -dJPEGQ=90 -r100 EVS-emb.pdf

 real  0m0.731s
 user  0m0.642s
 sys   0m0.072s

关于php - 像 Verisign/Docusign 一样非常非常快地将 PDF 转换为 PNG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31279742/

相关文章:

android - 在我的应用程序中,我想显示 PDF 或 .DOCX 的内容(包含文本和图像),以便它看起来像一个查看 android 应用程序?

ios - 使用 iOS 操作扩展将 PDF 导入自己的应用程序

java - 如何让图片和文字并排显示 itext

php - 使用 FallbackResource 将除一个目录之外的所有内容路由到 index.php

php - 如果满足条件,如何通过键从多维数组中删除数组 Php

javascript - 从 angular.js 表单生成 PDF

在超链接位置提取 PDF 文本

php - mysql server has gone away,序列化和锁等待错误

php - 使用 array_map 从数组中删除元素

php - 空白的 WordPress 登录页面