Search code examples
ghostscriptpostscript

How do I put a stamp on the upper right corner?


I'm trying to put a stamp on the top right corner of a PDF file. I have a PS file created from Excel using driver for HP Color LaserJet 4500 printed to file.

I am using GhostScript to create a PDF.

GSWIN32C.EXE @S:\Temp\PS\Options.txt

Here is the contents of the Options.txt file:

-sDEVICE=pdfwrite -q -dSAFER -dNOPAUSE
-sOUTPUTFILE="S:\Temp\PS\Sample.pdf" -dBATCH
"S:\Temp\PS\Stamp.txt"
"S:\Temp\PS\Sample.ps"

Here is the contents of Stamp.txt modified from here:

<<
   /EndPage
   {
     2 eq { pop false }
     {
         gsave
        /Helvetica_Bold 15 selectfont
       0 setgray
        475 767 moveto
        (STATE COPY) show
         grestore
         true
     } ifelse
   } bind
>> setpagedevice

The PDF is created just fine, but the stamp is causing me problems. The stamp shows very tiny on the upper left but flipped vertically.

Here is a section with the tiny stamp upper left: PDF with tiny stamp upper left

Here is the stamp enlarged 800%

Stamp enlarged 800%

On a multi-page PDF I want the stamp on all pages. I understand that using the /EndPage should let me do that.

So how do I get my stamp on the upper right corner?


Solution

  • I assume the problem with the stamp resides in the previous transformations. So I used scale to flip the stamp upright and adjusted until I got it in the right place.

    <<
     /EndPage
     {
       2 eq { pop false }
       {
         gsave      
        /Helvetica_Bold 15 selectfont 
        0 setgray
        10 10 scale
        375 17 moveto
        1 -1 scale
        (STATE COPY) show 
         grestore
         true
       } ifelse
     } bind
    >> setpagedevice
    

    I didn't test it but I assume using a different print driver to produce the PS file would give different results.