通过使用Ghostscript向PDF添加页边距来缩放页面中的图像 [英] Scale image in page by adding margins to PDF with Ghostscript

查看:201
本文介绍了通过使用Ghostscript向PDF添加页边距来缩放页面中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的客户希望我在其单页PDF的右上角和顶部边框中添加其他信息.该文件包含产品的图片以及度量和其他信息.我需要缩放页面的内容,以便可以清楚地看到右边/顶部的空白以添加额外的数据. 我已经在Windows中玩过Ghostscript,但是到目前为止,图像被裁剪掉了,或者什么也没有发生: gswin32c -sOutputFile = scaled2.pdf -dBATCH -dNOPAUSE -dDEVICEHEIGHTPOINTS = 312 -dDEVICEWIDTHPOINTS = 421 -dFIXEDMEDIA -dPDFFitPage -sDEVICE = pdfwrite -c<> setpagedevice" -f 255x195x175mm_EB_Fefco0427_FSN10

由于我通常不使用PDF,所以我在这里一无所有.

我需要PDF缩小图像并位于右下角. PDF大小应相同.

在Windows中可以通过命令行处理的任何其他解决方案也都可以.

解决方案

您可以查看我的答案中给出的代码不会简单地产生错误,我感到很惊讶,因为那不是有效的PostScript.

好的,所以您要么需要进行两次通过,要么自己计算比例.

在两次通过模型中,您首先应用缩放,这将为您提供一个PDF文件,其中内容仍占页面的大小,但是页面已被调整为较小的尺寸.然后,使用翻译和所需的最终媒体尺寸运行它,但不要设置FitPage.

要自己进行缩放,您需要将缩放比例添加到BeginPage命令中,而不是让Ghostscript为您执行缩放操作.这意味着您将不得不自己计算比例因子.

setpagedevice运算符的参数类似于:

<</BeginPage {0.5 0.5 scale 200 0 translate}>> setpagedevice

这将在每个方向上将内容缩小50%,并将原点向右移动100个点.显然,转换值将取决于比例因子以及原始和缩放媒体的大小.我会尝试对此进行检查,但您尚未提供示例PDF文件进行测试.

My customer wants me to add additional information to right and top border on their single page PDF. The file contains image of the product with measures and other info. I need to scale the content of the page, so that right/top margins would be clear to add extra data. I have played around with Ghostscript in Windows, but so far either the image is cropped out or nothing happens: gswin32c -sOutputFile=scaled2.pdf -dBATCH -dNOPAUSE -dDEVICEHEIGHTPOINTS=312 -dDEVICEWIDTHPOINTS=421 -dFIXEDMEDIA -dPDFFitPage -sDEVICE=pdfwrite -c "<> setpagedevice" -f 255x195x175mm_EB_Fefco0427_FSN1013.pdf

As I usually don't work with PDFs then I'm out of my debth here.

I need the image in PDF scaled smaller and sitting in the bottom-right corner. PDF size should be the same.

Any other solution that works in Windows and can be handled from commandline, is also OK.

解决方案

You can look at the code presented in my answer here. That shows you how to rescale the content of a PDF file to a different media size, and how to reposition the scaled content on the nominal output medium.

I'm rather surprised that -c "<>setpagedevice" -f doesn't simply produce an error, since that's not valid PostScript.

[edit]

OK so you either need to do two passes or do the calculation of the scale yourself.

In the two pass model you first apply the scaling, which will get you a PDF file where the content still fills the page, but the page has been resized to the smaller dimensions. You then run it with the translation and the desired final media size, but don't set FitPage.

To do the scaling yourself you would need to add the scale to the BeginPage command instead of having Ghostscript do it for you. That means you are going to have to calculate the scale factors yourself.

The parameter to the setpagedevice operator would look something like :

<</BeginPage {0.5 0.5 scale 200 0 translate}>> setpagedevice

That will scale the content down by 50% in each direction, and move the origin by 100 points to the right. Obviously the translate values will depend on the scale factor and the size of the original and scaled media. I would try this to check it, but you haven't supplied an example PDF file to test.

这篇关于通过使用Ghostscript向PDF添加页边距来缩放页面中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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