是否可以在Ghostscript中向PDF的每一页添加水印 [英] Is it possible in Ghostscript to add watermark to every page in PDF

查看:348
本文介绍了是否可以在Ghostscript中向PDF的每一页添加水印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ghostscript转换 PDF->许多JPEG 许多JPEG->许多PDF .我需要在每个转换的JPEG(PDF)页面上添加水印文本.可以仅使用Ghostscript和PostScript吗?

我找到的唯一方法:

gswin32c -q -sDEVICE = pdfwrite -dBATCH -dNOPAUSE -sOutputFile = output.pdf watermark.ps input.pdf

但这会在output.pdf的第一个单独页面上插入watermark.ps水印.

我可以直接在输出的PDF页面上执行此操作吗?

我可以直接在输出的JPEG页面上执行此操作吗?

<<
   /BeginPage
   { gsave
       /Helvetica_Bold 120 selectfont
       .85 setgray 130 70 moveto 50 rotate (Sample) show
     grestore
   } bind
>> setpagedevice

如果我使用/EndPage而不是/BeginPage-它表示setpagedevice不适用...

如何为/EndPage重新制作此脚本?

解决方案

位太大,无法发表评论,因此我添加了新答案. EndPage过程(请参阅《 PostScript语言参考手册》的第441页)在堆栈上增加了两个附加参数,到目前为止发出的页面数以及原因码.

您可以使用页面数来完成诸如双面打印之类的有趣事情,或者仅标记甚至是页面之类的东西,但是在这种情况下,我认为您不想要它,因此您只是从堆栈中弹出"它. /p>

原因码告诉您为什么页面被发出,您可能也不在乎,所以您只弹出值.

最后,EndPage必须向解释器返回一个布尔值,说明是否传输页面(这使您可以做其他有趣的事情,例如仅打印前10页,等等).

因此,您首先需要删除两个值,执行代码并返回一个布尔值.相当简单:

<<
   /EndPage
   { pop pop %% *BEFORE* gsave as that puts a gsave object on the stack
     gsave
     /Helvetica_Bold 120 selectfont
     .85 setgray 130 70 moveto 50 rotate (Sample) show
     grestore
     true %% transmit the page, set to false to not transmit the page
   } bind
>> setpagedevice

I convert PDF -> many JPEG and many JPEG -> many PDF using ghostscript. I need to add watermark text on every converted JPEG (PDF) page. Is it possible using only Ghostscript and PostScript?

The only way I found:

gswin32c -q -sDEVICE=pdfwrite -dBATCH -dNOPAUSE -sOutputFile=output.pdf watermark.ps input.pdf

But this will insert watermark.ps watermark on first separate page in output.pdf.

Can I do this on output PDF pages directly?

Can I do this on output JPEG pages directly?

<<
   /BeginPage
   { gsave
       /Helvetica_Bold 120 selectfont
       .85 setgray 130 70 moveto 50 rotate (Sample) show
     grestore
   } bind
>> setpagedevice

If I use /EndPage instead of /BeginPage - it says setpagedevice is not applicable...

How to remake this script for /EndPage?

解决方案

Bit too big for a comment, so I've added a new answer. The EndPage procedure (see page 441 of the PostScript Language Reference Manual) takes two additional parameters on the stack, a count of pages emitted so far, and a reason code.

You can use the count of pages to do interesting things like duplexing, or only marking even pages or whatever, but I assume in this case you don't want it, so you just 'pop' it from the stack.

The reason code tells you why the page is being emitted, again you probably don't care so you just pop the value.

Finally the EndPage must return a boolean value to the interpreter saying whether or not to transmit the page (this allows you to do other interesting things, like only printing the first 10 pages and so on).

So you need to initially remove two values, execute your code and return a boolean. Pretty trivial:

<<
   /EndPage
   { pop pop %% *BEFORE* gsave as that puts a gsave object on the stack
     gsave
     /Helvetica_Bold 120 selectfont
     .85 setgray 130 70 moveto 50 rotate (Sample) show
     grestore
     true %% transmit the page, set to false to not transmit the page
   } bind
>> setpagedevice

这篇关于是否可以在Ghostscript中向PDF的每一页添加水印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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