Linux Imagemagick 将多个图像转换为 pdf 大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9706046/
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 05:11:24  来源:igfitidea点击:

Imagemagick convert multiple images to pdf size

phplinuxpdfpdf-generationimagemagick

提问by Kenny

For a project I am running ImageMagick to convert several images (all of the same size 960x570) into a single PDF.

对于一个项目,我正在运行 ImageMagick 将多个图像(所有大小都相同 960x570)转换为单个 PDF。

The command I'm running is:

我正在运行的命令是:

convert *.jpg pdf/export.pdf

Since the images are all the same size I expect each PDF page to be equal in size but this is not the case as you can see in the screenshot below:

由于图像大小相同,我希望每个 PDF 页面的大小相同,但事实并非如此,如下面的屏幕截图所示:

example screenshot

示例截图

This is bit annoying since I don't know how I can force the size of each PDF page to be the same.

这有点烦人,因为我不知道如何强制每个 PDF 页面的大小相同。

I tested the PDF on both an android device, ubuntu pdf reader and adobe reader and they all show the different sizes.

我在 android 设备、ubuntu pdf 阅读器和 adobe 阅读器上测试了 PDF,它们都显示了不同的大小。

Thanks for helping!

感谢您的帮助!

EDIT1:After testing out a few more things as suggested by Marc B and Basti I managed to put the same size on the JPG (uploaded) images.

EDIT1:在按照 Marc B 和 Basti 的建议测试了一些其他东西之后,我设法在 JPG(上传的)图像上放置了相同的尺寸。

The problem still persists with the images that are generated using webkit2png (Python script that converts a webpage/html file to an image). After trying (almost?) everything in the convert command I can't get these generated images to shop up properly in the PDF as you can see below:

使用 webkit2png(将网页/html 文件转换为图像的 Python 脚本)生成的图像仍然存在问题。在尝试(几乎?)转换命令中的所有内容后,我无法让这些生成的图像在 PDF 中正确购物,如下所示:

enter image description here

在此处输入图片说明

Any help would be much appreciated!

任何帮助将非常感激!

采纳答案by Kenny

I found the solution:

我找到了解决方案:

I needed to add the following options to convert the image saved from webkit2png:

我需要添加以下选项来转换从 webkit2png 保存的图像:

-density 960x570 -units PixelsPerInch

I hope this helps other people out too in the future ;)

我希望这在未来也能帮助其他人;)

回答by Basti

After a few seconds of using google, I found this:

使用谷歌几秒钟后,我发现了这个:

-size <geometry> width and height of image

-size <geometry> width and height of image

Example given by them:

他们给出的例子:

$ convert -size 320x85 canvas:none -font Bookman-DemiItalic -pointsize 72 \ 
-draw "text 25,60 'Magick'" -channel RGBA -blur 0x6 -fill darkred -stroke magenta \ 
-draw "text 20,55 'Magick'" fuzzy-magick.png

http://www.imagemagick.org/script/convert.php

http://www.imagemagick.org/script/convert.php