imagemagick 从多个图像中制作固定大小的 pdf

imagemagick make pdf of a fixed size out of multiple images

我找到了这个问题的一些答案,但不知何故对我没有用(尽管从逻辑上讲,至少据我所知)

我有三个图像 file1.pngfile2.pngfile3.png 具有以下属性:

identify file*.png
file1.png PNG 4961x7016 4961x7016+0+0 8-bit sRGB 12.6135MiB 0.000u 0:00.000
file2.png PNG 4961x7016 4961x7016+0+0 8-bit sRGB 22.8132MiB 0.000u 0:00.000
file3.png PNG 4961x7016 4961x7016+0+0 8-bit sRGB 14.887MiB 0.000u 0:00.000

现在我使用这个 imagemagick 命令 convert file*.png -page A4 file.pdf 制作了一个 pdf,每页有一张图片。那个问题是,生成的 pdf 有 52 MB 太大了(因为输入图片也很大)。此外,我的 pdfviewer 显示生成的 pdf 的纸张大小为 25×36 mm(A10) 而不是所需的 210×297 mm(A4).

我已经尝试过调整大小,但不知何故我不太明白如何设置大小以获得 A4 输出(这是我现在的主要目标)。

有人知道为什么 page A4 不起作用或如何实际获得纸张大小为 A4 的输出 pdf 吗?

PS:

convert -version
Version: ImageMagick 7.0.10-25 Q16 x86_64 2020-08-01 https://imagemagick.org
Copyright: © 1999-2020 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenMP(4.5)
Delegates (built-in): bzlib cairo djvu fontconfig freetype heic jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png raqm raw rsvg tiff webp wmf x xml zlib

EDIT1(识别输出):

identify -verbose file.pdf
Image:
  Filename: file.pdf
  Format: PDF (Portable Document Format)
  Mime type: application/pdf
  Class: DirectClass
  Geometry: 71x101+0+0
  Resolution: 72x72
  Print size: 0.986111x1.40278
  Units: Undefined
  Colorspace: sRGB
  Type: TrueColorAlpha
  Base type: Undefined
  Endianness: Undefined
  Depth: 16/8-bit
[...]
identify file.pdf
file.pdf[0] PDF 71x101 71x101+0+0 16-bit sRGB 7412B 0.000u 0:00.000
file.pdf[1] PDF 71x101 71x101+0+0 16-bit sRGB 11518B 0.000u 0:00.000
file.pdf[2] PDF 71x101 71x101+0+0 16-bit sRGB 8394B 0.000u 0:00.000

EDIT2:在此处查看两个测试 png (https://mega.nz/folder/O4Fm1aoK#ppeQD4ZycDMKhC2DctJ-UA)(遗憾的是我无法将 pdf 上传到 Whosebug)

转换为 pdf 时仍然无效

在 ImageMagick 中,-page 是一个设置而不是运算符,因此不会调整大小。您需要使用 -resize 将每个图像调整为 A4 (595 x 842) 的像素尺寸。

convert file1.png file2.png file3.png -resize 595x842 result.pdf

这对我来说在 ImageMagick 上似乎工作正常。

convert -size 4961x7016 xc:red xc:green1 xc:blue -resize 595x842 result.pdf

identify result.pdf
result.pdf[0] PDF 595x841 595x841+0+0 16-bit sRGB 6215B 0.000u 0:00.002
result.pdf[1] PDF 595x841 595x841+0+0 16-bit sRGB 6215B 0.000u 0:00.001
result.pdf[2] PDF 595x841 595x841+0+0 16-bit sRGB 6215B 0.000u 0:00.000

identify -verbose result.pdf
Image:
  Filename: result.pdf
  Format: PDF (Portable Document Format)
  Mime type: application/pdf
  Class: DirectClass
  Geometry: 595x841+0+0
  Resolution: 72x72
  Print size: 8.26389x11.6806  <--- this is close to the expected size for A4 of 8 1/4 x 11 3/4 inches. 

您是否对英寸和厘米感到困惑?

如果我在 ImageMagick 中添加单位和密度,这对我有用。

convert Untitled* -units pixelsperinch -density 72 -resize 595x842 result.pdf

identify -verbose result.pdf

Image:
  Filename: result.pdf
  Format: PDF (Portable Document Format)
  Mime type: application/pdf
  Class: DirectClass
  Geometry: 595x841+0+0
  Resolution: 72x72
  Print size: 8.26389x11.6806
...

您可能发现了 ImageMagick 的不足。我认为需要提供单位和密度,因为 PNG 以 pixelspercentimeter 存储该信息,但 PDF 需要以 pixelsperinch 为单位。