使用Ghostscript将PDF呈现为PNG时,请遵循PDF中的MediaBox/CropBox. [英] Obey the MediaBox/CropBox in PDF when using Ghostscript to render a PDF to a PNG

查看:246
本文介绍了使用Ghostscript将PDF呈现为PNG时,请遵循PDF中的MediaBox/CropBox.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Ghostscript将以PDF呈现的单一图形绘图转换为PNG:

I've been using Ghostscript to convert my single figure plots rendered in PDF to PNG:

gswin32c -sDEVICE=png16m -r300x300 -sOutputFile=junk.png ^
         -dBATCH -dNOPAUSE Figure_001-a.pdf

在我得到PNG的意义上,它可以正常工作,并且其中包含绘图.

This works in the sense I get a PNG out and it contains the plot.

但是它也包含大量空白(示例源图像:

But it contains a huge amount of white space as well (an example source image: http://cdsweb.cern.ch/record/1258681/files/Figure_001-a.pdf).

如果在Acrobat中查看它,您会注意到情节周围没有空白.如果使用上面的命令行,您会发现绘图仅占空间的1/3.

If you view it in Acrobat you'll note there is no white space around the plot. If you use the above command line you'll find the plot is only about 1/3 of the space.

当使用EPS文件执行相同的操作时,我遇到了相同的问题.但是,有一个命令行参数-dEPSCrop可以传递给PS渲染引擎以注意BoundingBox.

When doing the same thing with an EPS file I run into the same problem. However, there is the command-line parameter -dEPSCrop that one can pass to get the PS rendering engine to pay attention to the BoundingBox.

我需要类似的参数来呈现PDF.我无法在文档中找到它(实际上甚至是-dEPSCrop都找不到).

I need the similar argument for rendering PDFs. I was not able to find it in docs (nor even the -dEPSCrop, actually).

推荐答案

我遇到了完全相同的问题.我通过添加-dUseArtBox开关对其进行了修复.

I had exactly the same issue. I fixed it by adding -dUseArtBox switch.

示例:

 /usr/bin/gs -dUseArtBox -dNOPAUSE -sDEVICE=pngalpha -sOutputFile=output.png input.pdf

注意:-dUseArtBox开关受支持自ghostscript版本9.07起

-dUseArtBox Sets the page size to the ArtBox rather than the MediaBox. The art box defines the extent of the page's meaningful content (including potential white space) as intended by the page's creator. The art box is likely to be the smallest box. It can be useful when one wants to crop the page as much as possible without losing the content.

-dUseArtBox Sets the page size to the ArtBox rather than the MediaBox. The art box defines the extent of the page's meaningful content (including potential white space) as intended by the page's creator. The art box is likely to be the smallest box. It can be useful when one wants to crop the page as much as possible without losing the content.

这篇关于使用Ghostscript将PDF呈现为PNG时,请遵循PDF中的MediaBox/CropBox.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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