我正在尝试使用命令行程序转换将PDF转换为图像(JPEG或PNG)。这是我正在转换的pdf文件之一。

我想让程序去掉多余的空白,并返回足够高质量的图像,以便上标可以轻松读取。

这是我目前最好的尝试。正如你所看到的,修剪工作很好,我只是需要锐化的分辨率相当多。这是我正在使用的命令:

convert -trim 24.pdf -resize 500% -quality 100 -sharpen 0x1.0 24-11.jpg

我试着做了以下有意识的决定:

调整它的大小(对分辨率没有影响) 尽可能提高质量 使用-锐化(我已经尝试了一系列值)

任何建议,请在最终的PNG/JPEG图像的分辨率更高,将非常感谢!


当前回答

在投票之前请注意,这个解决方案是针对使用图形界面的Gimp的,而不是使用命令行的ImageMagick的,但它作为一个替代方案对我来说效果非常好,这就是为什么我发现有必要在这里分享它。

按照这些简单的步骤从PDF文档中提取任何格式的图像

Download GIMP Image Manipulation Program Open the Program after installation Open the PDF document that you want to extract Images Select only the pages of the PDF document that you would want to extract images from. N/B: If you need only the cover images, select only the first page. Click open after selecting the pages that you want to extract images from Click on File menu when GIMP when the pages open Select Export as in the File menu Select your preferred file type by extension (say png) below the dialog box that pops up. Click on Export to export your image to your desired location. You can then check your file explorer for the exported image.

这是所有。

我希望这对你们有帮助

其他回答

这里的许多答案集中在使用magick(或其依赖项GhostScript)作为OP问题的设置,少数人建议使用Gimp作为替代,但没有描述为什么某些设置可能在不同情况下最有效。

对于OP“样本”,要求是一个清晰的修剪过的图像,尽可能小,但保持良好的可读性。这里的结果是96dpi在58 KB(一个非常小的增加矢量源54 KB),但仍然保持一个好的图像,即使放大。将其与上面接受的答案图像中的72 dpi (226 KB)进行比较。

关键是任何图像处理器都可以通过脚本从命令行批量运行,使用配置文件作为输入,所以这里IrfanView(带或不带GS)被设置为自动裁剪pdf页面,并在默认的96 dpi输出到PNG,仅使用16个灰色阴影的4个BitPerPixel颜色。 尺寸可以通过降低分辨率到72来进一步减小,但96是PNG屏幕显示的最佳设置。

使用这个命令行:

convert -geometry 3600x3600 -density 300x300 -quality 100 TEAM\ 4.pdf team4.png

这将正确地转换您所要求的文件。

通常我在原生分辨率下用'pdfimages'提取嵌入图像,然后使用ImageMagick的转换为所需的格式:

$ pdfimages -list fileName.pdf
$ pdfimages fileName.pdf fileName   # save in .ppm format
$ convert fileName-000.ppm fileName-000.png

这将生成最佳和最小的结果文件。

注意:对于有损的JPG嵌入图像,你必须使用-j:

$ pdfimages -j fileName.pdf fileName   # save in .jpg format

最近的“poppler-util”(0.50+,2016),你可以使用-所有保存有损为jpg和无损为png,所以一个简单的:

$ pdfimages -all fileName.pdf fileName

从PDF中提取总是最好的质量内容。

在很少提供的Win平台上,您必须下载最近的(0.68,2018)' popler -util'二进制从: http://blog.alivate.com.au/poppler-windows/

在mac电脑上使用预览其实很容易做到。你所要做的就是在预览中打开文件,并另存(或导出)png或jpeg格式,但要确保你在窗口底部使用至少300 dpi来获得高质量的图像。

我真的没有很好的转换成功[更新2020年5月:实际上:它几乎从来没有为我工作],但我有非常好的pdftoppm成功。下面是几个从PDF生成高质量图像的例子:

[Produces ~25 MB-sized files per pg] Output uncompressed .tif file format at 300 DPI into a folder called "images", with files being named pg-1.tif, pg-2.tif, pg-3.tif, etc: mkdir -p images && pdftoppm -tiff -r 300 mypdf.pdf images/pg [Produces ~1MB-sized files per pg] Output in .jpg format at 300 DPI: mkdir -p images && pdftoppm -jpeg -r 300 mypdf.pdf images/pg [Produces ~2MB-sized files per pg] Output in .jpg format at highest quality (least compression) and still at 300 DPI: mkdir -p images && pdftoppm -jpeg -jpegopt quality=100 -r 300 mypdf.pdf images/pg

要了解更多解释、选项和示例,请参阅我的完整答案:

https://askubuntu.com/questions/150100/extracting-embedded-images-from-a-pdf/1187844 1187844。

相关:

[如何将PDF转换为可搜索的PDF w/pdf2searchablepdf] https://askubuntu.com/questions/473843/how-to-turn-a-pdf-into-a-text-searchable-pdf/1187881#1187881 交联: 如何将一个PDF转换成JPG与命令行在Linux? https://unix.stackexchange.com/questions/11835/pdf-to-jpg-without-quality-loss-gscan2pdf/585574#585574