0

I am trying to use postscript to watermark postscript files. I am doing this with setpagedevice like so:

    <<
       /EndPage {
       exch pop 2 lt {
          /Times-Roman 40 selectfont
          .6 setgray 300 300 moveto 30 rotate (Watermark) show
          true}
          {false} ifelse
       } bind
    >> setpagedevice

    (file_to_watermark.ps) run

This works great, but I would like the watermark to be centered on the page, regardless of page size (this code needs to work for varying sizes of file_to_watermark.ps). My code right now is positioning the watermark based on specific coordinates, which obviously doesn't center the mark if a different file_to_watermark.ps is used with a different page size (i.e. legal, letter, etc.). Is there someway to retrieve the page size of the current file_to_watermark.ps and center-on-page the watermark based on that rather than predefined coordinates?

justbrown
  • 25
  • 5

1 Answers1

1

You could extract the current media size from the pagedevice dictionary:

currentpagedevice /PageSize get

which returns the width and height (in points) on the stack. You can then use the stringwidth operator to calculate the amount of space occupied by the given string when printed. There's no simple way to get the vertical height, but the pointsize is as good a guide as anything for Latin fonts.

Subtracting the string width from the page width and dividing by two should be good enough, similarly for the y co-ordinate.

For real printers, instead of using the MediaSize the initial clip is sometimes a better bet:

initclip clippath flattenpath pathbbox
Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
KenS
  • 30,202
  • 3
  • 34
  • 51