Landscape viewing and printing

There are several ways to produce landscape pages when using PostScript and PDF. This document describes how to produce portrait and landscape documents for processing by Ghostscript.

Document Structuring Conventions

The DSC requires the use of PostScript comments which are used by document managers such as GSview. They are documented in an appendix of the PostScript Language Reference Manual, 2nd edition. If a file claims to comply with the DSC, then it will start with a line like:
  %!PS-Adobe-3.0
This indicates DSC version 3 - it should not be confused with PostScript Level 3. Other DSC comments all start with %%. Some example DSC comments are:
  %%Pages: 20
  %%Orientation: Landscape
  %%LanguageLevel: 2
A big problem with using DSC comments is that many programs and printer drivers produce incorrect DSC comments.

GSview

To view correctly in GSview, the document must contain information about the page size and the orientation. GSview obtains this information from the DSC comments only - it ignores any PostScript code to set the page size or orientation. The page size should be given in a line
  %%DocumentMedia: a4 595 842 80 () ()
The parameters are name, width (in PostScript pts = 1/72"), height, weight (gsm), colour, and pre-printed form. The orientation should be given by the line
  %%Orientation: Portrait
If orientation is Landscape, the image is rotated 90 degrees clockwise. The image width is thus the page height. If Portrait, the image is unchanged.

Printing

For printing, the page size is set by the PostScript command setpagedevice. The DSC comments are ignored. To set the page size to A4 (210x297mm = 595x842pts), the required command is
  << /PageSize [595 842] >> setpagedevice
At the same time as setting the page size, you can also set the orientation. This doesn't make much sense for printers which have only one paper orientation. For printers which write to roll film, the orientation can determine whether the image is across the film, or lengthwise down the film. To request a 90 degree rotation:
  << /PageSize [595 842] /Orientation 3 >> setpagedevice

Portrait

Most pages are printed in Portrait. An example portrait PostScript file is:

%!PS-Adobe-3.0
%%Orientation: Portrait
%%DocumentMedia: a4 595 842 80 () ()
%%Pages: 1
%%EndComments
%%EndProlog
%%BeginSetup
  % A4, unrotated
  << /PageSize [595 842] /Orientation 0 >> setpagedevice
%%EndSetup
%%Page: 1 1
%%BeginPageSetup
%%EndPageSetup
  % This is standard portrait orientation on A4 paper.
  /Helvetica findfont 220 scalefont setfont
  72 600 moveto
  (ABC) show
  showpage
%%Trailer
%%EOF

Rotated image on Portrait paper

This is the most common method for "landscape". GSview will display it correctly, provided that it includes %%Orientation: Landscape. This method will print correctly. When converted to PDF, you will need to turn your monitor on its side. A later section shows how to do landscape on portrait paper such that PDF is displayed correctly. An example PostScript file is:

%!PS-Adobe-3.0
%%Orientation: Landscape
%%DocumentMedia: a4 595 842 80 () ()
%%Pages: 1
%%EndComments
%%EndProlog
%%BeginSetup
  << /PageSize [595 842] /Orientation 0 >> setpagedevice
%%EndSetup
%%Page: 1 1
%%BeginPageSetup
  90 rotate 0 -595 translate
%%EndPageSetup
  % This page prints on standard A4 portrait paper.
  % You need to turn your head 90 degrees to view this page
  % in GSview, or after converting to PDF.
  /Helvetica findfont 220 scalefont setfont
  72 72 moveto
  (ABCD) show
  showpage
%%Trailer
%%EOF

Landscape on Landscape paper

This will view correctly in GSview, and convert correctly to PDF and bitmaps using Ghostscript. When you try to print it you may end up with:
This is undesirable. For this reason, I recommend against using this method for producing landscape orientation.

An example PostScript file is:

%!PS-Adobe-3.0
%%Orientation: Portrait
%%DocumentMedia: a4land 842 595 80 () ()
%%Pages: 1
%%EndComments
%%EndProlog
%%BeginSetup
  % A4 landscape orientation
  << /PageSize [842 595] /Orientation 0 >> setpagedevice
%%EndSetup
%%Page: 1 1
%%BeginPageSetup
%%EndPageSetup
  % This page prints on landscape A4 portrait paper.
  % Some printers will print this page unrotated with right
  % part of the image truncated where it falls off the page.
  % "%%DocumentMedia: (XXX) 842 595" and "%%Orientation: Portrait"
  % allows normal viewing in GSview.
  % "/PageSize [842 595] /Orientation 0" allows normal viewing 
  % after converting to PDF.
  % This is NOT the preferred way to do landscape documents in 
  % PostScript and PDF, although it is valid.
  /Helvetica findfont 220 scalefont setfont
  72 72 moveto
  (ABCD) show
  showpage
%%Trailer
%%EOF

Landscape on Portrait paper

In GSview and when converted to PDF it will view as:

Depending on the output device, this may print correctly, or it may print with the right part of the image truncated. PDF and bitmap output from Ghostscript will be the same as viewed. An example PostScript file is:

%!PS-Adobe-3.0
%%Orientation: Landscape
%%DocumentMedia: a4 595 842 80 () ()
%%Pages: 1
%%EndComments
%%EndProlog
%%BeginSetup
  % A4, rotated 90 degrees ACW
  << /PageSize [595 842] /Orientation 3 >> setpagedevice
%%EndSetup
%%Page: 1 1
%%BeginPageSetup
  90 rotate 0 -595 translate
%%EndPageSetup
  % This page prints on standard A4 portrait paper.
  % "%%Orientation: Landscape" allows normal viewing in GSview.
  % "/Orientation 3" allows normal viewing after converting to PDF.
  % This is the preferred way to do landscape documents in 
  % PostScript, especially when converting to PDF.
  /Helvetica findfont 220 scalefont setfont
  72 72 moveto
  (ABCD) show
  showpage
%%Trailer
%%EOF
Note that the only difference between this method and the earlier "Rotated image on Portait paper" is that the setpagedevice /Orientation is 3, not 0. Hand editing the PostScript file can fix that!


Home
6 November 1998 by Russell Lang