obelixk
obelixk

Reputation: 33

How can I make a program overlay text ON TOP of a PostScript file?

How can I make a Ghostscript overlay text on top of a PostScript file?

I found part of a solution here: How can I make a program overlay text on a postscript file? which suggests to do:

gs -o figLabel.pdf -sDEVICE=pdfwrite \
   -c "/Helvetica findfont 15 scalefont setfont 50 200 moveto (text) show" \
   -f fig.eps` 

However in that case the text is behind the image.

Is there an option in Ghostscript to force the text to be in front of the image?

Upvotes: 3

Views: 1179

Answers (1)

luser droog
luser droog

Reputation: 19504

PostScript uses an opaque painting model, so each new thing drawn obscures anything previously drawn. In your command line, the text is drawn and then the EPS file is drawn. It sounds like you want the reverse behavior. So do

gs  -o figLabel.pdf -sDEVICE=pdfwrite \
    -f fig.eps \
    -c "/Helvetica findfont 15 scalefont setfont 50 200 moveto (text) show showpage"

This should work IF the EPS file obeys the rule that it should not call showpage itself. Otherwise, we'll need to add workarounds for that.

If the EPS file calls showpage (even though it ought not to do this), we need to redefine the name /showpage so it does nothing, and save the old definition to call at the end.

gs  -o figLabel.pdf -sDEVICE=pdfwrite \
    -c "/realshowpage /showpage load def /showpage {} def" \
    -f fig.eps \
    -c "/Helvetica findfont 15 scalefont setfont 50 200 moveto (text) show realshowpage"

Upvotes: 3

Related Questions