Linux 如何使用 ImageMagick 控制 PDF 纸张大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11693137/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 13:56:54  来源:igfitidea点击:

How do I control PDF paper size with ImageMagick?

linuxpdfimagemagick

提问by mackstann

I have 16 jpg files which are around 920x1200 pixels (the widths slightly differ but heights are all 1200). I'm trying to join them into a pdf with:

我有 16 个 jpg 文件,大约为 920x1200 像素(宽度略有不同,但高度均为 1200)。我正在尝试将它们加入到 pdf 中:

convert *.jpg foo.pdf

But the resulting paper size is 1.53x2 inches. If I pass the arguments -page Letter, the page size ends up being a bewildering 1.02x1.32 inches. What is going wrong here? All of the information I can find suggests that this should work. I just want a document that consists of 16 letter-size pages.

但最终的纸张尺寸为 1.53x2 英寸。如果我传递参数-page Letter,页面大小最终会变成令人眼花缭乱的 1.02x1.32 英寸。这里出了什么问题?我能找到的所有信息都表明这应该有效。我只想要一个由 16 个信纸大小的页面组成的文档。

回答by Kurt Pfeifle

For Letter, you need to specify the size as 792x612 PostScript points. Therefor try this command:

对于 Letter,您需要将大小指定为 792x612 PostScript 点。因此试试这个命令:

 convert \
    in1.jpg \
    in2.jpg \
    in3.jpg \
    in4.jpg \
    in5.jpg \
   -gravity center \
   -resize 792x612\! \
    letter.pdf

Works for me with ImageMagick version 6.7.8-3 2012-07-19 Q16on Mac OS X:

在 Mac OS X 上使用 ImageMagick 版本6.7.8-3 2012-07-19 Q16对我有用

identify -format "%f[%s] :  %W x %H\n" letter.pdf
  letter.pdf[0] :  792 x 612
  letter.pdf[1] :  792 x 612
  letter.pdf[2] :  792 x 612
  letter.pdf[3] :  792 x 612
  letter.pdf[4] :  792 x 612

Or

或者

pdfinfo -f 1 -l 5 letter.pdf 
  Title:          _
  Producer:       ImageMagick 6.7.8-3 2012-07-19 Q16 http://www.imagemagick.org
  CreationDate:   Fri Jul 27 22:28:00 2012
  ModDate:        Fri Jul 27 22:28:00 2012
  Tagged:         no
  Form:           none
  Pages:          5
  Encrypted:      no
  Page    1 size: 792 x 612 pts (letter)
  Page    1 rot:  0
  Page    2 size: 792 x 612 pts (letter)
  Page    2 rot:  0
  Page    3 size: 792 x 612 pts (letter)
  Page    3 rot:  0
  Page    4 size: 792 x 612 pts (letter)
  Page    4 rot:  0
  Page    5 size: 792 x 612 pts (letter)
  Page    5 rot:  0
  File size:      178642 bytes
  Optimized:      no
  PDF version:    1.3

回答by apurkrt

I just succeeded with convert file.mng -page letter file.pdf

我刚刚成功 convert file.mng -page letter file.pdf

回答by Forest

This question is pretty old, but I had a similar problem and I think I found the solution.

这个问题很老了,但我遇到了类似的问题,我想我找到了解决方案。

The documentation for the -page option says "This option is used in concert with -density", but the relationship between the options seems a little unclear, possibly because the documentation is geared towards raster images.

-page 选项的文档说“此选项与 -density 一起使用”,但选项之间的关系似乎有点不清楚,可能是因为文档是针对光栅图像的。

From experimenting with the settings, I found that the pdf page size can be controlled by combining -page -density and -units. The documentationfor -page shows that letter is the same as entering 612 x 792. Combining -density 72 with -units pixelsperinch will give you (612px /72px) * 1in = 8.5in.

通过对设置的试验,我发现可以通过组合 -page -density 和 -units 来控制 pdf 页面大小。-page的文档显示该字母与输入 612 x 792 相同。将 -密度 72 与 -units pixelperinch 结合将得到 (612px /72px) * 1in = 8.5in。

convert *.jpg -units pixelsperinch -density 72 -page letter foo.pdfshould do what the original poster wanted.

convert *.jpg -units pixelsperinch -density 72 -page letter foo.pdf应该做原始海报想要的。