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

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

问题描述

我使用 ghostscript 转换 PDF -> many JPEGmany JPEG -> many PDF.我需要在每个转换后的 JPEG (PDF) 页面上添加水印文本.是否可以只使用 Ghostscript 和 PostScript?

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?

我发现的唯一方法:

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

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

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

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

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

Can I do this on output PDF pages directly?

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

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

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

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

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

How to remake this script for /EndPage?

推荐答案

评论太大了,所以我添加了一个新答案.EndPage 过程(请参阅 PostScript 语言参考手册的第 441 页)在堆栈上采用两个额外的参数、到目前为止发出的页数和原因代码.

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.

最后,EndPage 必须向解释器返回一个布尔值,说明是否传输页面(这允许你做其他有趣的事情,比如只打印前 10 页等等).

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天全站免登陆