ImageMagick 转换在将 PDF 转换为 PNG 时添加空格
ImageMagick convert adds whitespace when converting PDF to PNG
我正在使用 ImageMagick 将以下 PDF 转换为 PNG 文件。
Click here to download the PDF from IMSLP (Permalink如果直接下载坏了)
在 PDF 查看器中它看起来不错:
但是当使用 convert -density 300 -background white -alpha off -alpha remove file.pdf /tmp/file.png
转换时
图像有较大的白边:
我不想 trim 之后的图像,我只是希望 ImageMagick 以某种方式尊重视口,或者观看信息正在 PDF 中编码。有谁知道哪个命令行参数可能启用此行为?
编辑 10.03.2022:我在 Alpine Linux docker 图像中使用 ImageMagick 7.1.0.16 和 Ghostscript 9.55.0。
我在使用 Ghostscript 9.54 的 ImageMagick 6.9.12-42 中没有得到你的额外保证金。但是改变密度似乎没有任何效果。
convert -density 300 -background white file.pdf[1] x2.png
这些问题可能是格式错误的 PDF。它是如何创建的?另外,您使用的是什么版本的 Ghostscript?可能是GS版本问题。
如果这是一个扫描的 PDF,它是矢量 PDF 中的光栅图像 shell,那么您可以只使用 pdfimages 来提取光栅文件。参见 https://manpages.debian.org/testing/poppler-utils/pdfimages.1.en.html
来自KenS was exactly what I was looking for - the PDF defines a CropBox that ImageMagick 7.1.0 was not using by default. The solution therefore is to modify the command to include the following -define
信息的提示:
convert -define pdf:use-cropbox=true file.pdf /tmp/file.png
谢谢大家的帮助!
我正在使用 ImageMagick 将以下 PDF 转换为 PNG 文件。
Click here to download the PDF from IMSLP (Permalink如果直接下载坏了)
在 PDF 查看器中它看起来不错:
但是当使用 convert -density 300 -background white -alpha off -alpha remove file.pdf /tmp/file.png
图像有较大的白边:
我不想 trim 之后的图像,我只是希望 ImageMagick 以某种方式尊重视口,或者观看信息正在 PDF 中编码。有谁知道哪个命令行参数可能启用此行为?
编辑 10.03.2022:我在 Alpine Linux docker 图像中使用 ImageMagick 7.1.0.16 和 Ghostscript 9.55.0。
我在使用 Ghostscript 9.54 的 ImageMagick 6.9.12-42 中没有得到你的额外保证金。但是改变密度似乎没有任何效果。
convert -density 300 -background white file.pdf[1] x2.png
这些问题可能是格式错误的 PDF。它是如何创建的?另外,您使用的是什么版本的 Ghostscript?可能是GS版本问题。
如果这是一个扫描的 PDF,它是矢量 PDF 中的光栅图像 shell,那么您可以只使用 pdfimages 来提取光栅文件。参见 https://manpages.debian.org/testing/poppler-utils/pdfimages.1.en.html
来自KenS was exactly what I was looking for - the PDF defines a CropBox that ImageMagick 7.1.0 was not using by default. The solution therefore is to modify the command to include the following -define
信息的提示:
convert -define pdf:use-cropbox=true file.pdf /tmp/file.png
谢谢大家的帮助!