【问题标题】:Convert PDF to PNG very very fast like Verisign/Docusign像 Verisign/Docusign 一样非常快速地将 PDF 转换为 PNG
【发布时间】:2015-07-07 21:36:30
【问题描述】:

我一直在使用 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 和其他项目放在输出视图。据我所知,您无法使用直接 PDF 做到这一点,这就是他们将所有内容都转换为图像的原因。

【问题讨论】:

  • 你试过 MuPDF 吗?
  • 您能提供(链接到)您的示例 PDF 吗?
  • 另外,您测试了哪些版本的 Ghostscript 和 ImageMagick?
  • 我无法在技术上链接示例 PDF,因为它是包含个人信息的安全文档。我可以说它的36页纯文本。这是一个有文本和图像的,当然转换时间要长得多classidex.com/Test/EVS.pdf 我正在运行 php 5.4,这就是我所知道的
  • @Dagon 我找不到有关用于 PHP/Java 的 MuPDF 的任何信息。如果你能指出我的方向,我愿意尝试一下。我只看到它谈论Android集成

标签: php pdf


【解决方案1】:

我在具有 4 GB RAM 的 4 岁 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 并不完全符合犹太教规,因为来自 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

【讨论】:

    【解决方案2】:

    我使用 ubuntu,这个命令将所有 pdf 转换为 images\png

    for f in *.pdf; do convert -quality 100 $f ${f%%.*}.jpg; done
    

    【讨论】:

      猜你喜欢
      • 2012-09-15
      • 2010-10-13
      • 2017-04-15
      • 1970-01-01
      • 2015-12-30
      • 1970-01-01
      • 2018-12-24
      • 2012-10-16
      • 2017-07-05
      相关资源
      最近更新 更多