radistao
radistao

Reputation: 15504

Run Ghostscript (GS) with PostScript as a command line argument (but not a file)

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.

Upvotes: 2

Views: 1969

Answers (2)

luser droog
luser droog

Reputation: 19504

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.

Upvotes: 0

KenS
KenS

Reputation: 31159

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.

Upvotes: 1

Related Questions