Ghostscript:播种某些区域? [英] Ghostscript : Crop Certain Area?

查看:63
本文介绍了Ghostscript:播种某些区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ghostscript的新手。

I am new to ghostscript.

我有一个包含卡片的pdf文件。我想将这张卡剪裁掉。

I have a pdf which contains a card. i want to crop that card out.

当前,由于对文档的理解,我只能将pdf转换为图像,但是在剪裁方面没有运气。
看到了其他所有相关问题,但对我却没有用。

Currently with the understanding of document i am only able to convert the pdf to image but have no luck in cropping. Saw every other related question but there are not working for me.

这是我在批处理文件中用于将pdf转换为图像的代码:

This is code i used in batch file for converting the pdf to image:

"C:\Program Files\gs\gs9.50\bin\gswin64c.exe" -sDEVICE=png16m -r300 -o c:\users\jen\desktop\pdf.png -f "c:\users\jen\desktop\pdf.pdf
pause 

现在我也不知道该如何裁剪?
i想在某些位置进行裁剪,例如:左:28顶部:524宽度:492.3高度:161

now i don't know how to crop with it too ? i want to crop at certain postition like: Left:28 Top:524 Width:492.3 Height:161

编辑

示例PDF文件 THE_PDF_TO_CROP 。我想将pdf的蓝色区域剪切为图像。

Example PDF file THE_PDF_TO_CROP. I want to cutout the blue area of pdf to image.

推荐答案

您需要设置几个参数;首先,您需要指定输出位图的宽度和高度,可以使用 -dDEVIC EHEIGHTPOINTS -dDEVICEWIDTHPOINTS ,或者您也可以使用 -g< x> x< y>指定输出大小(以像素为单位) ; 其中,和是x和y方向上的像素数。显然,这将取决于分辨率。

You need to set several parameters; Firstly you need to specify the width and height of the output bitmap. You can use either -dDEVICEHEIGHTPOINTS and -dDEVICEWIDTHPOINTS, or alternatively you can specify the output size in pixels using -g<x>x<y> where and are the number of pixels in the x and y directions. Obviously that will vary depending on the resolution. You can't (obviously) use fractional pixels.

如果使用 -dDEVICEWIDTHPOINTS -dDEVICEHEIGHTPOINTS ,那么您还需要设置 -dFIXEDMEDIA 来告诉解释器不要使用PDF文件中的介质大小。

If you use -dDEVICEWIDTHPOINTS and -dDEVICEHEIGHTPOINTS then you also need to set -dFIXEDMEDIA to tell the interpreter not to use the media size from the PDF file instead.

这样就可以创建正确大小的输出位图。如果仅尝试使用这种方式呈现文件,则会看到它仅呈现页面左下角的一部分。因此,现在您需要移动内容,以便所需的部分位于媒体的左下角。您可以通过使用PageOffset PostScript运算符来做到这一点。

So that shoould create an output bitmap of the correct size. If you try rendering your file using just that, you will see that it renders just a portion of the page from the bottom left. So now you need to shift the content around so that the portion you want lies at the bottom left of the media. You can do that by using the PageOffset PostScript operator.

您没有给出任何数字,也没有提供示例文件,所以可以说(出于示例目的)您想要呈现1英寸乘2英寸的文档部分。进一步说,您要渲染的部分从左边缘开始2.5英寸,从底边缘开始1.5英寸。

You haven't given any numbers, nor supplied an example file, so lets say (for the sake of example) that you want to render a 1 inch by 2 inch portion of the document. Lets further say that you the part you want rendered starts 2.5 inches from the left edge, and 1.5 inches from the bottom edge.

合适的命令行为:

gs -sDEVICEWIDTHPOINTS=72 -dDEVICEHEIGHTPOINTS=144 -dFIXEDMEDIA -r300 -sDEVICE=png16m -o out.png -c "<</PageOffset [-180 -108]>> setpagedevice" -f input.pdf

PDF(和PostScript)单位为1/72英寸,因此72 = 1英寸,144 = 2英寸。您需要左右移动页面的原点,这就是为什么PageOffset的值为负。

Note that PDF (and PostScript) units are 1/72 inch so 72 = 1 inch, 144 = 2 inches. You need to shift the origin of the page down and left, which is why the values for PageOffset are negative.

如果这对您不起作用,我需要要查看您的PDF文件,您需要告诉我您使用的是哪个版本的Ghostscript。

If that doesn't work for you I'll need to see your PDF file and you'll need to tell me which version of Ghostscript you are using.

这篇关于Ghostscript:播种某些区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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