简体   繁体   English

Imagemagick:在读取时将PDF格式化为设定的分辨率

[英]Imagemagick: Rasterize the PDF to a set resolution when reading it in

I want to generate thumbnails of PDFs at a fixed width (548px wide, with the height determined by the PDF page aspect ratio). 我想生成固定宽度的PDF缩略图(548px宽,高度由PDF页面宽高比决定)。 With ImageMagick, I can do this with the command: 使用ImageMagick,我可以使用以下命令执行此操作:

$ convert -density 300 -resize 548x input.pdf thumbnail.png

This works for arbitrary sized PDFs, however, the larger the PDF the longer it takes. 这适用于任意大小的PDF,但PDF越大,所需的时间越长。 From the documentation I understand that this is because ImageMagick first has to read in the PDF and rasterize it (at 300 DPI), before scaling it down. 从文档中我了解到这是因为ImageMagick首先必须读取PDF并对其进行光栅化(以300 DPI为单位),然后再缩小它。 This obviously takes longer and more memory the larger the PDF is. 这显然需要更长的时间和更多的内存,PDF越大。

My question is: Can we tell ImageMagick to rasterize the PDF to a set resolution when reading it in (something like 2 or 3 times larger than the thumbnail needs to be) before scaling it down and outputting the PDF? 我的问题是:在缩小PDF并输出PDF之前,我们能否告诉ImageMagick将PDF格式化为设定的分辨率(比缩略图需要的大2或3倍)? This should allow our conversion to run in roughly the same amount of time regardless of the PDF size. 这应该允许我们的转换在大致相同的时间内运行,而不管PDF大小。

We can do this ourselves manually by reading the PDF resolution first and then calculating the appropriate DPI to generate a rasterized PDF of the right size, but this seems like a bit of a hack and I would expect something like this built into ImageMagick. 我们可以通过首先读取PDF分辨率然后计算适当的DPI以生成合适大小的光栅化PDF来手动完成,但这看起来有点像黑客,我希望像ImageMagick内置这样的东西。

This is not possible with the current version of ImageMagick (6.8.8-7). 目前版本的ImageMagick(6.8.8-7)无法实现这一点。 We found your post here and added the following feature that will be available in ImageMagick (6.8.8-8): 我们在此处找到了您的帖子,并添加了ImageMagick(6.8.8-8)中提供的以下功能:

You can scale a PDF to a width of 548 pixels with the following command: 您可以使用以下命令将PDF缩放为548像素的宽度:

$ convert -define psd:fit-page=548x input.pdf thumbnail.png

If you create an image with another DPI than the default (72 DPI) you will have to resize it afterwards: 如果使用其他DPI创建的图像不是默认值(72 DPI),则必须在之后调整其大小:

$ convert -density 300 -define psd:fit-page=548x input.pdf -resize 548x thumbnail.png

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM