2

For a plotting project of mine I was following the How-to by Eric Weeks to rescale my post-script page so that one unit matches 1 cm of length. The header of my PS file looks like this:

%!PS
matrix currentmatrix /originmat exch def
/umatrix {originmat matrix concatmatrix setmatrix} def
[28.3465 0 0 28.3465 0 0] umatrix

It does the job but the other thing I need is to resize the page from US Letter to A4. According to, e.g., Postscript - document size I should setpagedevice with something like:

<< /PageSize [595 842] >> setpagedevice

However I cannot make it work. When I put it in front of the matrix redefinition, it takes no effect. When I put it after the matrix redefinition (even translating the new size to cm) it resets the matrix scale and the page still comes out as US Letter, only the drawing is scaled down because the coordinates are now in pts.

How can I both rescale the page and define its size?

Edit: I am attaching a MWE presenting my problem. This draws a rectangle that would plot a box around the page, leaving a 10-mm margin if the page was A4-sized. On a letter-sized medium it shows how the paper is shorter but wider.

%!PS
matrix currentmatrix /originmat exch def
/umatrix {originmat matrix concatmatrix setmatrix} def
[28.3465 0 0 28.3465 0 0] umatrix
0.020000 setlinewidth
1.0 1.0 moveto 1.0 27.7 lineto 20.0 27.7 lineto 20 1.0 lineto 1.0 1.0 lineto
stroke
Frigo
  • 362
  • 2
  • 17
  • How are you printing the PostScript file? You could be running into rescaling in the backend. BTW the first snippet can probably be simplified to `[28.3465 0 0 28.3465 0 0] concat`. – luser droog Feb 26 '21 at 01:24
  • I don't have a PS printer at my disposal, so I typically print it from `evince` through a PCL driver, or I convert to PDF with `ps2pdf` and then print in the same way. All my printers allow me to override paper size and print Letter on A4 media, as long as the actual graphic does not run out of the paper. – Frigo Feb 26 '21 at 08:52
  • As for the command `[28.3465 0 0 28.3465 0 0] concat`, yes, it just shifts the graph on the paper for me. I should clean it up because I have another shifting step in my code afterwards, anyway. Thank you for pointing it out. – Frigo Feb 26 '21 at 09:00
  • 1
    When converting to PDF, this snippet may help: `[ {Catalog} << /ViewerPreferences << /PrintScaling /None >> >> /PUT pdfmark` . Not sure about how to affect the PCL path. – luser droog Feb 26 '21 at 15:07
  • 1
    I find that my original plot is not lost even when drawing beyond the Letter page boundary. When, for instance, I convert my original PS to PDF with GhostScript, I can specify A4 size with `-sDEVICE=pdfwrite -sPAPERSIZE=a4` and the plot reappears in the now bigger margins. This gives me a passable workaround, similar to what you propose. Of course the original PS still remains Letter-sized. – Frigo Feb 26 '21 at 19:44

1 Answers1

0

Is there another call of setpagedevice in the file which sets the letter format? The call executed last will win for the page size, and setting up the matrix differently has do be done after that call since it resets all graphic settings when setting up the page device.

If you cannot find where it is being called, you could redefine the setpagedevice operator in userdict. That might work or not, depending on how the whole PostScript file is constructed. In the redefinition you would create a new dict operand to setpagedevice, copy all entries but replace any PageSize by your desired value.

This might do:

userdict /setpagedevice {
    dup length dict begin
        {
            1 index /PageSize eq {
                pop [595 842]
            } if
            def
        } forall
    currentdict
    end
    setpagedevice
} bind put
  • Thank you. I tried but either I do not know how to use this routine properly or it does not help. Anyway it inspired me to add a minimum working example to my question. There is indeed no other occurrence of `setpagedevice` or any other medium-changing command in my code. Could you perhaps show how your approach is applied to the MWE? – Frigo Apr 01 '21 at 08:42