ImageMagick Convert 将 PDF 转换为 PNG 时添加空格
我正在使用 ImageMagick 将以下 PDF 转换为 PNG 文件。
单击此处下载 PDF IMSLP (永久链接(如果直接下载已损坏)
在 PDF 查看器中看起来不错:
但使用 convert -密度 300 -background White -alpha off -alpha remove file.pdf /tmp/file.png
进行转换时,
图像会得到一个大白边:
我不想事后修剪图像,我只是希望 ImageMagick 以某种方式尊重视口,或者无论如何,查看信息都被编码在 PDF 中。有谁知道哪个命令行参数可能会启用此行为?
编辑 10.03.2022:我在 Alpine Linux docker 镜像中使用 ImageMagick 7.1.0.16 和 Ghostscript 9.55.0。
I'm using ImageMagick to convert the following PDF to an PNG file.
Click here to download the PDF from IMSLP (Permalink if the direct download is broken)
In a PDF viewer it looks nice:
but when converting with convert -density 300 -background white -alpha off -alpha remove file.pdf /tmp/file.png
the image gets a large white margin:
I do not want to trim the image afterwards, I just want ImageMagick to somehow respect the view-port or however that viewing information is being encoded in the PDF. Does anyone know which command-line parameter might enable this behavior?
Edit 10.03.2022: I'm using ImageMagick 7.1.0.16 with Ghostscript 9.55.0 inside an Alpine Linux docker image.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
KenS 的提示正是我所寻找的 - PDF 定义了 ImageMagick 7.1.0 未使用的 CropBox默认。因此,解决方案是修改命令以包含以下
-定义
信息:谢谢大家的帮助!
The hint from 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
information:Thank you all for your help!
我在使用 Ghostscript 9.54 的 ImageMagick 6.9.12-42 中没有获得额外的余量。但改变密度似乎没有任何效果。
问题可能是 PDF 格式错误。它是如何创建的?另外您使用的是哪个版本的 Ghostscript?可能是GS版本问题。
如果这是一个扫描的 PDF,它是矢量 PDF 外壳中的光栅图像,那么您可以只使用 pdfimages 来提取光栅文件。请参阅 https://manpages.debian.org/testing/poppler -utils/pdfimages.1.en.html
I do not get your extra margin in ImageMagick 6.9.12-42 using Ghostscript 9.54. But changing the density does not seem to have any effect.
The issues may be a malformed PDF. How was it created? Also what version of Ghostscript are you using? It could be a GS version issue.
If this was a scanned PDF that is a raster image in a vector PDF shell, then you could just use pdfimages to extract the raster files. See https://manpages.debian.org/testing/poppler-utils/pdfimages.1.en.html