Captain Crunch
Captain Crunch

Reputation: 11

Postscript: Draw Logo in upper left corner in any page size

I need to draw Logo to the existing pdf files into the top left corner. Currently, I hard-coded the y position in the postscript. I need to change the y position as per the current page size of the using pdf file. As same like Logo, I need to draw rectangle also. there also i hard coded the parameters.

My Script ---

<<
    /PageSize [595 842]
    /EndPage {
        exch pop 2 lt {
            gsave
                20 720 translate     
                40 40 scale        
                77                   
                81                  
                8                    
                [77 0 0 -81 0 81]      
                (Logo.jpg) (r) file /DCTDecode filter 
                false                 
                3                   
                colorimage  
            grestore
            gsave           
                newpath 10 10 60 820 rectstroke
                /_WM_str (Office of XXXX,XXXX) def
                /Helvetica [40 0 0 40 0 0] selectfont
                /DeviceRGB setcolorspace
                0.96 0.96 0.96 setcolor
                currentpagedevice/PageSize get aload pop
                2 div exch 12 div exch translate 90 rotate
                newpath
                _WM_str stringwidth pop 2 div neg 0 moveto
                _WM_str show                
            grestore
            true
        } { false } ifelse
    }bind
>>setpagedevice

Using following command, i created output file.

gs -q -sDEVICE=pdfwrite -dBATCH -dNOSAFER -dNOPAUSE -sOutputFile=output.pdf -dPDFFitPage -dAutoRotatePages=/None -f test.ps 1001.pdf

I need to know, how to position logo in upper left corner and draw rectangle from bottom to top around the logo like stamping?

Example:

image

Upvotes: 1

Views: 2110

Answers (1)

KenS
KenS

Reputation: 31199

You can extract the current media size from the page device dictionary :

currentpagedevice /PageSize get

that gives you the width and height of the media, and you can calculate from that where the top left corner is.

The layout of the portion you are adding is up to you, but you should be able to use the width and height to calculate an appropriate scale factor, as well as figuring out where the remaining portions of your graphic will go.

%!
<<
    /PageSize [595 842]
    /EndPage {
        exch pop 2 lt {
            currentpagedevice /PageSize get  %% stack has array [width height]
            0 0 moveto                       %% start at bottom left
            dup 1 get                        %% copy array, get height
            0 exch lineto                    %% line to top left 
            dup 0 get                        %% copy array get width
            10 div cvi 0 rlineto             %% horizontal line from top left, 1/10th of width
            1 get                            %% get height from array
            neg 0 exch rlineto               %% vertical line to bottom of page
            closepath                        %% close path to origin
            0.5 setgray stroke
            true
        } { false } ifelse
    }bind
>>setpagedevice

Upvotes: 2

Related Questions