Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help

Postscript Document Structuring Conventions

Postscript's DSC (Document Structuring Conventions) are lines in the postscript file that help printers and help programs that need to manipulate the contents - for example a program like psselect which extracts pages needs to know where pages begin and end and which parts of the initialisation are still required. DSC lines begin with '%%' - as can comment lines! In consequence some applications take DSC lines more seriously than other applications do - for example, sometimes '%%Orientation: Landscape' is ignored and sometimes it isn't.

Postscript files that follow the conventions should have at least the following structure

%!PS-Adobe-3.0
%%Pages:
%%EndComments
%%BeginProlog
%%EndProlog
%%BeginSetup
%%EndSetup
%%Page:
%%BeginPageSetup
%%EndPageSetup
%%PageTrailer
%%Trailer
%%EOF
Some applications are a little careless about which section of the file to put postscript commands in.

Media selection

We have had problems with clashes between options in DSC lines and printing options given on the command line. In this section we'll look at some issues relating to A3/A4 paper size selection

lp/lpr/CUPS

Options mentioned in the CUPS documentation to select paper size include
   -o media=A4
   -o media=Upper

DSC

The options supported in postscript depend on the postscript version. Before "%%EndComments" you may see a line like
%%DocumentPageSizes: A4
but such lines were superceded in PS-Adobe-3.0 by "%%DocumentMedia", which needs 6 arguments - a string, 3 numbers and 2 strings. The arguments are: a tag, width, height, weight, paper color, special feature. 0 is used to replace unwanted numbers, and ( ) to replace strings. Examples are
%%DocumentMedia: PlainLetter 612 792 75 white ( )
%%DocumentMedia: Letter 792 612 0 white Plain 
The tag string is used in subsequent "PageMedia" lines which can be in the global defaults section or the per-page DSC sections. There's also a PaperSize option. Here are some examples

Printers and Viewers

Recent versions of ghostscript will recognise most of the above options, but might have trouble with the per-page options.

Printers will use a default paper tray unless otherwise specified from the command line, but they'll need to process the postscript page by page to use the correct media type

Here 4 example files (which may not be completely compliant or ideally minimal) that you can use to test your printers.
File 1 - A4 using DocumentMedia
%!PS-Adobe-3.0
%%DocumentMedia: A4 595 842 0 () ()
%%BeginDefaults
%%PageMedia: A4
%%EndDefaults
%%BeginSetup
%%PaperSize: A4
%%EndSetup
%%EndComments

/Times-Roman findfont
15 scalefont
setfont
296 421 moveto
(Testing) show
showpage
File 2 - A3 using DocumentMedia
%!PS-Adobe-3.0
%%DocumentMedia: A3 842 1190 0 () ()
%%BeginDefaults
%%PageMedia: A3
%%EndDefaults
%%BeginSetup
%%PaperSize: A3
%%EndSetup
%%EndComments

/Times-Roman findfont
15 scalefont
setfont
421 595 moveto
(Testing) show
showpage
File 3 - A4 using setpagedevice
%!PS-Adobe-3.0
%%DocumentPaperSizes: A4
%%EndComments
/setpagedevice where
{ pop 1 dict
  dup /PageSize [ 595 842 ] put
  setpagedevice
} if

/Times-Roman findfont
15 scalefont
setfont
296 421 moveto
(Testing) show
showpage
File 4 - A3 using setpagedevice
%!PS-Adobe-3.0
%%DocumentPaperSizes: A3
%%EndComments
/setpagedevice where
{ pop 1 dict
  dup /PageSize [ 842 1190 ] put
  setpagedevice
} if

/Times-Roman findfont
15 scalefont
setfont
421 595 moveto
(Testing) show
showpage
On our linux/CUPS system with a Canon iR 5570 printer

References

© Cambridge University Engineering Dept
Information provided by Tim Love (tpl)
Last updated: September 2006