2

I execute a Ghostscript (gs) command with the following arguments:

gs -q -dBATCH -dNOPAUSE -sDEVICE=jpeg -dJPEGQ=98 -r96 -dTextAlphaBits=4 \
   -dGraphicsAlphaBits=4 -sOutputFile=target.jpg -f watermark.ps input.pdf

where watermark.ps is a PostScript file with script like here:

Is it possible in Ghostscript to add watermark to every page in PDF

Is it possible to use that PostScript inline, I mean putting watermark.ps text directly to the command line avoiding the file reading?

According to this doc http://www.ghostscript.com/doc/9.18/Use.htm#Input_control it's possible using -c or -s switches, but I can't figure out how to merge that .ps file to one line? How to treat new lines in PS? Maybe I should use -c for every line? I was not able to google any gs example with inline PS.

Community
  • 1
  • 1
radistao
  • 14,889
  • 11
  • 66
  • 92

2 Answers2

1

Rather a disjointed questions....

Yes it is possible to add a watermark to every page, no its not simple when the input is PDF, however my answer from the question you quoted should work.

I should give up on trying to do this with -c and -f. What do you think you gain that way anyway ? However the simple answer is that newline is (not surprisingly) simply a white space character in PostScript. Its not a special token, you can replace it with any other white space character.

If you want to use PostScript, then there's no point in googling for Ghostscript, you need to look for PostScript. Its a programming language, and Adobe released the specification when they produced the early interpreters, back in the 1980s. The specification (now at level 3) is still available online.

KenS
  • 30,202
  • 3
  • 34
  • 51
  • i googled both post and ghost script - almost all my request redirected to http://www.ghostscript.com/doc/9.18/Use.htm or just pure Post Script specification – radistao Nov 29 '16 at 15:23
  • Well, the PostScript specification is what you need to answer questions regarding PostScript. – KenS Nov 29 '16 at 19:35
0

Based on your command line, I'm assuming you have a unix shell. You can substitute the result of a command in most shells with `cmd args...` or $(cmd args).

bash> echo $(cat watermark.ps)

With gs's -c <ps-code> option, you can inject the code into the execution at that point.

luser droog
  • 18,988
  • 3
  • 53
  • 105
  • "I'm assuming you have a unix shell" - no. Actually it is even not gs command, it is a java library Ghost4J. It uses the same command interface as in command line, but obviously i can't use an input/output stream pipe-line there. – radistao Nov 29 '16 at 15:20
  • >inject the code into the execution at that point could you explain what this means (inject code)? – radistao Nov 29 '16 at 15:21
  • "Inject" was probably the wrong word. I meant "insert". ... You can put the `-c code` option between two filenames, and gs will execute the code between the files. – luser droog Nov 29 '16 at 15:32