【问题标题】:Combine png's into a PDF without rerasterizing将 png 合并为 PDF 而无需重新光栅化
【发布时间】:2020-12-06 21:07:21
【问题描述】:

我正在使用 ImageMagick 的 convert 将 6 个 PNG 文件合并为一个 PDF:

Bytes   File name
-----   ---------
44927   002.png
43507   003.png
71375   004.png
56448   005.png
61696   006.png
57694   007.png

# Both generate a 533,378 byte PDF
convert 00?.png OutputFile.pdf
convert 00?.png -density 200x200 OutputFile.pdf

图像是来自平板扫描仪的 200 DPI 黑白扫描。 PNG 文件总计 335,647 KB,但生成的 OutputFile.pdf 为 533,378 KB。

这个尺寸膨胀是因为重新光栅化吗?

如何指定convert 以保留现有像素?

以防万一,我在 Windows 10 64 位 (cygcheck -p convert | grep -i imagemagick) 上使用 Cygwin 的 ImageMagick 7.0.10.27-1。

【问题讨论】:

  • PNGS 已经光栅化。但我怀疑 PDF 会将光栅图像未压缩为 PDF 矢量外壳中的原始数据(未格式化为 PNG)。我不知道有什么方法可以告诉 ImageMagick 让它们保持压缩。您可以查看其他工具将光栅图像转换为 PDF 文件
  • 谢谢,但似乎发生了默认压缩,不足以弥补每个单色像素的 8 位。其他工具的调查需要时间,所以为了方便,我求助于convert。我将在文件大小上获得大约 2 倍的命中率。

标签: imagemagick-convert


【解决方案1】:

下面的pdfimages 输出表明存在一些默认压缩(在ratio 列下)。我记得在convertsome time ago 的深处进行了管道铺设。 depth 选项不会减少每像素的位数。从下面的测试中,depth 也没有与monochrome 结合使用。此外,奇怪的是monochrome 导致 DPI 从 200 变为 508 或 509。

文件大小膨胀的一个可能原因是使用 8 位/像素。从之前链接到上面的convert 的测试来看,压缩似乎挤出了每像素不需要的 8 位所浪费的空间。然而,从 PDF 文件的大小来看,如果这是真的,那么它并不能真正弥补所有的文件大小膨胀。

# 1st default, monochrome, 200dpi, depth 1, and combinations
convert 00?.png  default.pdf
convert -monochrome 00?.png mono.pdf
convert -monochrome 00?.png -density 200x200 mono200.pdf
convert -depth 1 00?.png  depth1.pdf
convert -monochrome -depth 1 00?.png  monoDepth1.pdf

ls -l *.pdf

   510362 default.pdf
   510350 mono.pdf
   510362 mono200.pdf
   510362 depth1.pdf
   510374 monoDepth1.pdf

for file in *.pdf ; do echo ' ' ; echo $file: ; pdfimages -list $file ; done

default.pdf:
page   num  type   width height color comp bpc  enc interp  object ID x-ppi y-ppi size ratio
--------------------------------------------------------------------------------------------
   1     0 image    1700  2167  gray    1   8  image  no         8  0   200   200 70.1K 1.9%
   2     1 image    1700  2145  gray    1   8  image  no        22  0   200   200 67.8K 1.9%
   3     2 image    1700  2139  gray    1   8  image  no        36  0   200   200 97.8K 2.8%
   4     3 image    1700  2156  gray    1   8  image  no        50  0   200   200 80.2K 2.2%
   5     4 image    1700  2156  gray    1   8  image  no        64  0   200   200 89.9K 2.5%
   6     5 image    1700  2150  gray    1   8  image  no        78  0   200   200 85.2K 2.4%

mono.pdf:
page   num  type   width height color comp bpc  enc interp  object ID x-ppi y-ppi size ratio
--------------------------------------------------------------------------------------------
   1     0 image    1700  2167  gray    1   8  image  no         8  0   200   200 70.1K 1.9%
   2     1 image    1700  2145  gray    1   8  image  no        22  0   200   200 67.8K 1.9%
   3     2 image    1700  2139  gray    1   8  image  no        36  0   200   200 97.8K 2.8%
   4     3 image    1700  2156  gray    1   8  image  no        50  0   200   200 80.2K 2.2%
   5     4 image    1700  2156  gray    1   8  image  no        64  0   200   200 89.9K 2.5%
   6     5 image    1700  2150  gray    1   8  image  no        78  0   200   200 85.2K 2.4%

mono200.pdf:
page   num  type   width height color comp bpc  enc interp  object ID x-ppi y-ppi size ratio
--------------------------------------------------------------------------------------------
   1     0 image    1700  2167  gray    1   8  image  no         8  0   508   508 70.1K 1.9%
   2     1 image    1700  2145  gray    1   8  image  no        22  0   508   508 67.8K 1.9%
   3     2 image    1700  2139  gray    1   8  image  no        36  0   508   509 97.8K 2.8%
   4     3 image    1700  2156  gray    1   8  image  no        50  0   508   508 80.2K 2.2%
   5     4 image    1700  2156  gray    1   8  image  no        64  0   508   508 89.9K 2.5%
   6     5 image    1700  2150  gray    1   8  image  no        78  0   508   509 85.2K 2.4%

depth1.pdf:
page   num  type   width height color comp bpc  enc interp  object ID x-ppi y-ppi size ratio
--------------------------------------------------------------------------------------------
   1     0 image    1700  2167  gray    1   8  image  no         8  0   200   200 70.1K 1.9%
   2     1 image    1700  2145  gray    1   8  image  no        22  0   200   200 67.8K 1.9%
   3     2 image    1700  2139  gray    1   8  image  no        36  0   200   200 97.8K 2.8%
   4     3 image    1700  2156  gray    1   8  image  no        50  0   200   200 80.2K 2.2%
   5     4 image    1700  2156  gray    1   8  image  no        64  0   200   200 89.9K 2.5%
   6     5 image    1700  2150  gray    1   8  image  no        78  0   200   200 85.2K 2.4%

monoDepth1.pdf:
page   num  type   width height color comp bpc  enc interp  object ID x-ppi y-ppi size ratio
--------------------------------------------------------------------------------------------
   1     0 image    1700  2167  gray    1   8  image  no         8  0   200   200 70.1K 1.9%
   2     1 image    1700  2145  gray    1   8  image  no        22  0   200   200 67.8K 1.9%
   3     2 image    1700  2139  gray    1   8  image  no        36  0   200   200 97.8K 2.8%
   4     3 image    1700  2156  gray    1   8  image  no        50  0   200   200 80.2K 2.2%
   5     4 image    1700  2156  gray    1   8  image  no        64  0   200   200 89.9K 2.5%
   6     5 image    1700  2150  gray    1   8  image  no        78  0   200   200 85.2K 2.4%

【讨论】:

    猜你喜欢
    • 2011-06-30
    • 2015-10-27
    • 1970-01-01
    • 2018-10-26
    • 2012-02-14
    • 2015-07-20
    • 1970-01-01
    • 2021-05-01
    • 2013-04-13
    相关资源
    最近更新 更多