有效地生成巨大的pdf文件的缩略图? [英] Efficient thumbnail generation of huge pdf file?

查看:133
本文介绍了有效地生成巨大的pdf文件的缩略图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在开发的系统中,我们正在生成缩略图作为工作流的一部分. 有时pdf文件很大(打印尺寸3平方米),并且可以包含巨大的位图图像.

In a system I'm working on we're generating thumbnails as part of the workflow. Sometimes the pdf files are quite large (print size 3m2) and can contain huge bitmap images.

有没有能够生成缩略图的程序,它们可以针对内存占用进行优化?来处理如此大的pdf文件?

Are there thumbnail generation capable programs that are optimized for memory footprint handling such large pdf files?

生成的缩略图可以是png或jpg.

The resulting thumbnail can be png or jpg.

推荐答案

ImageMagick 是我所有使用的我的CLI图形,因此也许可以为您工作:

ImageMagick is what I use for all my CLI graphics, so maybe it can work for you:

convert foo.pdf foo-%png

这将产生三个单独的PNG文件:

This produces three separate PNG files:

foo-0.png
foo-1.png
foo-2.png

要仅创建一个缩略图,请将PDF视为数组([0]是第一页,[1]是第二页,依此类推):

To create only one thumbnail, treat the PDF as if it were an array ([0] is the first page, [1] is the second, etc.):

convert foo.pdf[0] foo-thumb.png

由于担心内存,使用-cache选项可以限制内存使用:

Since you're worrying about memory, with the -cache option, you can restrict memory usage:

-缓存阈值 像素缓存可用的兆字节内存.

-cache threshold megabytes of memory available to the pixel cache.

图像像素存储在内存中 直到已达到 threshold 兆字节的内存 消耗.后续像素操作 被缓存在磁盘上.操作到 记忆明显更快,但 如果您的计算机没有 您有足够的可用内存 可能要调整此阈值 值.

Image pixels are stored in memory until threshold megabytes of memory have been consumed. Subsequent pixel operations are cached on disk. Operations to memory are significantly faster but if your computer does not have a sufficient amount of free memory you may want to adjust this threshold value.

因此,要为PDF文件创建缩略图并调整其大小,可以运行以下命令,该命令的最大内存使用量约为20mb:

So to thumbnail a PDF file and resize it,, you could run this command which should have a max memory usage of around 20mb:

convert -cache 20 foo.pdf[0] -resize 10%x10% foo-thumb.png

或者您可以使用-density指定输出密度(900可以将其缩小很多):

Or you could use -density to specify the output density (900 scales it down quite a lot):

convert -cache 20 foo.pdf[0] -density 900 foo-thumb.png

这篇关于有效地生成巨大的pdf文件的缩略图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆