Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

page orientation for printing

Status
Not open for further replies.

rborysov

Programmer
Dec 17, 2003
5
UA
I assigned PageSize to [792 612] and properly rotated coordinate system to deal with landscape orientation.
GhostView displays my file correctly.

But the printer (LJ1200) always outputs my PS as portrait.
"%%Orientation: Landscape" comment takes no effect.

What is wrong?
How should I indicate the orientation for the printer?

Thanks.
 
I doubt very much that your Laserjet pays any attention at all to comments. Comments are ignored by the PostScript interpreter; they are just comments!

The actual code to force orientation or paper tray or anything else device dependent will need to use the "setpagedevice" operator.

To set pagesize:

Code:
<< /PageSize [792 612] >> setpagedevice

Looking at the PPD for the LJ1200 doesn't reveal any special setpagedevice dictionary for forcing Landscape. The code above should work!

Thomas D. Greer
 
You could also do that with a rotate command.

/PaperRotate { PL 0 translate 90 rotate PL PH /PL exch def /PH exch def } def
/APays { APort PaperRotate } def %8.5x11 Landscape
/APort { /PL 612 def /PH 792 def } def %8.5x11 portrait

With these commands defined, you just have to execute APort for portrait, and APays (Paysage=landscape in French) for landscape. The origin stays at the bottom left of the paper. PL is the width (horizontal dimension) of the paper, and PH is the height.
 
Here is my code:

%declare global variables
/pagemarginH 0 def
/pagemarginV 0 def
/A4WIDTH 595 def
/A4HEIGHT 842 def

%procedure to set page orientation, size and margins
/setPageLayoutMargins
%in: (layout), pagemarginH, pagemarginV
%out: -
%set globals: /pagelayout, /pagewidth and /pageheight
{
3 -1 roll dup dup
(LAYOUT_PORTRAIT) eq

{
<</PageSize [A4WIDTH A4HEIGHT]>> setpagedevice
%change PS coordinate sytem to ordinary screen one
0 842 translate
1 -1 scale
}
if

(LAYOUT_LANDSCAPE) eq
{
<</PageSize [A4HEIGHT A4WIDTH]>> setpagedevice
90 rotate
1 -1 scale
}
if

/pagelayout exch def

currentpagedevice /PageSize get aload pop
/pageheight exch def
/pagewidth exch def

dup /pagemarginV exch def exch
dup /pagemarginH exch def exch
moveto
}
def

Nevertheless, even under FreeBSD (lpr command) postscript printer (LJ1200) always outputs A4 as portrait despite initial stack value (layout). Under Windows (GhostView) the same printing takes place.

I'm sure the code above contains one or more logical errors, because printing occurs not properly. At the same time, I can't point to the place they are in, because e.g. GhostView always rotates my pages properly when media orientation autodetection checked.

What's wrong?

Thanks,
Roman
 
One thing I see immediately is that, due to your negative X-scaling, that the text will print backwards!

Tell me what your goal is? Obviously you want to set a page size.

Orientation is really a meaningless concept to a PostScript interpreter. Either a page is sized for example 612 x 792, or it's sized 792 x 612. Orientation only comes into play with devices. Based on a page size, a device driver may send the output to a paper tray with a certain &quot;orientation&quot; within the device. If this choice is ambiguous, then print dialogs/drivers allow the user to force an orientation.

My point is, just setting the proper page size should be sufficient.

What are you trying to accomplish with the rotation and scaling, though?

Thomas D. Greer
Providing PostScript & PDF
Training, Development & Consulting
 
I think I see what you're trying to do. You want to move the origin to UpperLeft corner, and then make Y increase DOWN the page, right?

You can't use scale for that. Scale affects the underlying coordinate system. Does that make sense?

When you do a 1 -1 scale, yes, things will flow top-down. But they'll also be upside down, because you've inverted the entire coordinate system.

Think of it this way. What does a font contain? Not just characters, but actual glyphs, little drawings of the letters. Those little drawings use PostScript, and they use moveto, lineto, etc. When you do &quot;scalefont&quot;, you are scaling the font coordinate system up to the current transformation matrix (YOUR coordinate system), where everything is flipped on the Y-axis. So, your letters will be drawn upside down.

What you need to do is not flip or negate the Y axis, but only the Y coordinate value. You can do that by, for example, redefining moveto. Here's some sample code:

Code:
%!PS

/setLayout
{ % sets proper page size
  % repositions origin to &quot;top left&quot;
  
  % in: pageSizeX pageSizeY
  % pageSizeX and pageSizeY are numbers in points
  % example: 612 792 or 792 612
  
  /Y exch def
  /X exch def
  
  <</PageSize [X Y]>> setpagedevice  % Page Size (orientation implicit)
  0 Y translate   % moves origin to upper-left corner

  % need to redefine moveto to invert Y value
  /mt /moveto load def  % store the &quot;real&quot; moveto
  /moveto
  { % now write our own
    % on stack Y, X
    neg mt  % negate the Y, then call real moveto
  } bind def
  
} bind def


792 612 setLayout

/Courier 24 selectfont
0 30 moveto (This near the top) show
0 72 moveto (This an inch &quot;down&quot;) show
0 144 moveto (This two inches &quot;down&quot;) show

showpage

Thomas D. Greer
Providing PostScript & PDF
Training, Development & Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top