[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21. PostScript

@sf{Debian}: `gs'
@sf{Debian}: `psutils'
@sf{WWW}: ftp://www.gnu.org/pub/gnu/ghostscript/
@sf{WWW}: ftp://ftp.dcs.ed.ac.uk/pub/ajcd/
@sf{WWW}: http://www.cappella.demon.co.uk/tinyfiles/tinymenu.html

PostScript is a programming language, used to describe the way a "page" (usually a physical sheet of paper) should look. PostScript files are text files containing the PostScript commands for drawing images to be printed on pages.

Like plain text files, PostScript files are commonly found on the Internet (and are used by commercial printers) because, as with plain text, they can be shared across platforms and hardware without difficulty. The same PostScript file can be output on a high-end display or printed on a low-end printer, to the best of that hardware's capability. PostScript is a compact and elegant format.

While it's possible to write directly in the PostScript language, and some people have become adept at programming PostScript, so many tools and applications convert files to and from PostScript that you don't have to. See section Converting Plain Text for Output, for a way to convert plain text into PostScript.

Ghostscript is a free implementation of the PostScript language. The gs tool is a Ghostscript interpreter that is used to convert files from PostScript to other formats, usually for printing to a non-PostScript printer (see section Preparing a PostScript File for Printing). The ghostview tool is used to preview PostScript files on the screen (see section Previewing a PostScript File).

EPS, or Encapsulated PostScript, is a file format that describes the contents of a box within a page. EPS files can be embedded in the page of a PostScript file, and are therefore commonly used when inserting an illustration into a document (for example, all of the illustrations in the Cookbook are EPS format files). You can view and print EPS files just as you would PostScript files.

This chapter includes recipes for formatting and manipulating PostScript files. Recipes are separated according to whether they work on the individual, logical pages in a PostScript file (the numbered pages in the file that are not necessarily the physical pages of output), and those that work on the entire file as a whole.

Unless otherwise indicated, the tools in this chapter are part of Angus Duggan's PSUtils package. These tools can be useful for other purposes than those described below; see their respective man pages for more details.

21.1 Manipulating PostScript Pages  Manipulating the pages of a PostScript file.
21.2 Manipulating PostScript Documents  Manipulating a PostScript file as a whole.
21.3 Converting PostScript  Converting PostScript to other formats.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.1 Manipulating PostScript Pages

These recipes work on individual pages of PostScript files, and not the entire file itself.

21.1.1 Extracting DVI Pages to PostScript  Extracting DVI pages to PostScript.
21.1.2 Extracting Pages from a PostScript File  Extracting pages from a PostScript file.
21.1.3 Combining PostScript Pages  Combining PostScript pages.
21.1.4 Arranging PostScript Pages in Signatures  Putting PostScript pages into signatures.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.1.1 Extracting DVI Pages to PostScript

To extract specific pages of a DVI ("DeVice Independent") file to PostScript, use dvips and give the page or hyphenated page ranges to output with the `-pp' option.

By default, dvips will output to the printer; to save the PostScript output to a file, give the file name to be used for output with the `-o' option.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.1.2 Extracting Pages from a PostScript File

Use psselect to select pages from a PostScript file; when you give an input file, it outputs a new PostScript file containing the specified pages.

Give the pages to select as arguments to the `-p' option; you can list single pages and ranges of pages separated by commas. Give ranges as two numbers between a hyphen; thus, `4-6' specifies pages four through six, inclusive. If you omit the first number in a pair, the first page is assumed, and if you omit the last number, the last page is assumed. Pages are written to the new file in the order they are specified.

In the preceding example, page 2 is selected twice.

Prefix a number with an underscore (`_') to indicate that the given page number is relative to the last page, counting backwards toward the first page.

Use the `-e' option to select all even-numbered pages, and use the `-o' option to select all odd-numbered pages.

Use an underscore (`_') alone to insert a blank page, and use `-r' to output pages in reverse order.

NOTE: The same result as the preceding example above could have been done by omitting the `-r' option and just listing the three pages in the reverse order:

 
$ psselect -p99,79,59 newsletter.ps selection.ps RET


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.1.3 Combining PostScript Pages

Use psnup to print multiple PostScript pages on a single sheet of paper; give as an option the number of pages to be combined (or put "up") on each sheet.

To specify the paper size, give the name of a standard paper size as an argument to the `-p' option: a3, a4, a5, b5, letter, legal, tabloid, statement, executive, folio, quarto, or 10x14. You can also specify any height and width with the `-h' and `-w' options; units can be specified in centimeters (followed by `cm') or inches (followed by `in'). If no size is specified, psnup assumes a paper size of a4.

Use the `-l' option when pages are in landscape orientation (rotated 90 degrees counter-clockwise from portrait orientation), and `-r' when pages are in seascape orientation (rotated 90 degrees clockwise from portrait orientation).

Pages are placed in "row-major" layout in the output file, where logical pages are placed in rows across the page. Use the `-c' option to specify a "column-major" layout, where logical pages are placed in columns down the page. Scale the size of the pages by giving a percentage to multiply the page size by as an argument to the `-s' option; for example, `-s .5' scales pages to 50 percent of their original size.

To draw a border around each page, specify the border's width in points as an argument to the `-d' option (if no width is specified, a value of 1 is assumed).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.1.4 Arranging PostScript Pages in Signatures

A signature is a group of pages in a document corresponding to sheets of paper folded and bound; these pages are normally not in sequential order in a document (for example, in a document with eight-page signatures, page 8 and page 1 might both be printed on the same sheet of paper).

To rearrange the pages of a PostScript file by signature--usually for printing the file as a book or booklet--use psbook. Give as arguments the name of the PostScript file to read from and the name to use for the output file; it reads the contents of the first, rearranges the pages, and then writes the PostScript output to the second file.

By default, psbook uses one signature for the entire file. If the file doesn't contain a multiple of four pages, it adds blank pages to the end.

To specify the size of the signature to use--in other words, the number of pages that will appear on a single piece of paper--give the number as an argument to the `-s' option. Signature size is always a multiple of four.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.2 Manipulating PostScript Documents

These recipes work on a PostScript document as a whole.

21.2.1 Resizing a PostScript Document  Resizing a PostScript file.
21.2.2 Combining PostScript Documents  Combining PostScript files.
21.2.3 Arranging a PostScript Document in a Booklet  Making PostScript booklets.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.2.1 Resizing a PostScript Document

Use psresize to resize a PostScript file. It takes as arguments the file to resize and the output file to write to; you must also specify the page size of the output file, using the same format as with the psnup tool: use `-p' or `-h' and `-w' to specify the size of the output file, and use `-P' to specify the size of the input file (see section Combining PostScript Pages).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.2.2 Combining PostScript Documents

Use psmerge to concatenate and merge multiple PostScript files into a single file. Give the names of the files to be merged as arguments, and psmerge outputs them to the standard output in the order given. You can also specify an output file name with the `-o' option (don't put any spaces between the file name and the option).

NOTE: As of this writing, psmerge only works with PostScript files that were made with the same application--which means, for example, that you can merge multiple files made with TeX, or multiple files made with xfig, but not a combination of the two.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.2.3 Arranging a PostScript Document in a Booklet

To arrange the pages in a PostScript file to make booklets, rearrange the file in a signature with psbook, use psnup to arrange the pages--two to a printed page in landscape mode--and then use pstops to output first the odd and then the even pages.

The trick to doing this properly is to first determine exactly what you need to do and then calculate the proper measurements for use with pstops.

Then, to print the booklet, you send `odd.ps' to the printer, load the printed pages in the manual feed tray and then send `even.ps' to the printer. This prints the odd and even pages on opposite sides of the sheets.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.3 Converting PostScript

These recipes show how to convert PostScript files to other formats. See also the recipes for preparing PostScript files for printing, Preparing a PostScript File for Printing.

21.3.1 Converting PostScript to PDF  
21.3.2 Converting PostScript to Plain Text  Converting PostScript to plain text.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.3.1 Converting PostScript to PDF

Use ps2pdf, part of the gs ("Ghostscript") package, to convert a PostScript file to PDF. Give as arguments the name of the PostScript file to read from, and the name of the PDF file to write to.

This command writes a new file in PDF format called `sutra.pdf'. The original file, `sutra.ps', is not altered.

NOTE: To make proper PDF conversions, make sure that you have gs version 6.01 or higher installed; use the `-v' option with gs to output the installed version.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.3.2 Converting PostScript to Plain Text

To convert a PostScript file to plain text, use ps2ascii. Give as arguments the name of the PostScript file to read from, and the name of the text file to write to.

This command writes a text file called `sutra.txt'. The original file, `sutra.ps', is not altered.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated using texi2html