|[<--] [Cover] [Table of Contents] [Concept Index] [Program Index] [-->]|
Debian: `gs' Debian: `psutils' WWW: ftp://www.gnu.org/pub/gnu/ghostscript/ WWW: ftp://ftp.dcs.ed.ac.uk/pub/ajcd/ 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 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 Preparing a PostScript File for Printing). The
ghostview tool is used to preview
PostScript files on the screen (see 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
These recipes work on individual pages of PostScript files, and not the entire file itself.
To extract specific pages of a DVI ("DeVice Independent") file to
dvips and give the page or hyphenated page ranges
to output with the `-pp' option.
$ dvips -pp1 abstract.dvi [RET]
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.
$ dvips -pp137-146 -o abstract.ps abstract.dvi [RET]
psselect to select pages from a PostScript file; when you
give an input file, it outputs a new PostScript file containing the
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.
$ psselect -p47 newsletter.ps selection.ps [RET]
$ psselect -p1-10,104,23-28,2 newsletter.ps selection.ps [RET]
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.
$ psselect -p_2-_10 newsletter.ps selection.ps [RET]
$ psselect -p_2-10 newsletter.ps selection.ps [RET]
Use the `-e' option to select all even-numbered pages, and use the `-o' option to select all odd-numbered pages.
$ psselect -e newsletter.ps even.ps [RET]
$ psselect -o newsletter.ps odd.ps [RET]
Use an underscore (`_') alone to insert a blank page, and use `-r' to output pages in reverse order.
$ psselect -p_1-_10,_,1-10 newsletter.ps selection.ps [RET]
$ psselect -p59,79,99 -r newsletter.ps selection.ps [RET]
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]
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.
$ psnup -2 single.ps double.ps [RET]
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).
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.
$ psbook newsletter.ps newsletter.bound.ps [RET]
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.
$ psbook -s8 newsletter.ps newsletter.bound.ps [RET]
These recipes work on a PostScript document as a whole.
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
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 Combining PostScript Pages).
$ psresize -pletter double.ps doublet.ps [RET]
psmerge to concatenate and merge multiple PostScript files
into a single file. Give the names of the files to be merged as
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).
$ psmerge -oslideshow.ps slide1.ps slide2.ps slide3.ps [RET]
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.
To arrange the pages in a PostScript file to make booklets, rearrange
the file in a signature with
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
$ psbook newsletter.ps newsletter.signature.ps [RET]
$ psnup -l -pletter -2 -s.7 newsletter.signature.ps > newsletter.2up.ps [RET]
$ pstops "2:0(1in,0in)" newsletter.2up.ps > odd.ps [RET]
$ pstops "2:-1(1in,0in)" newsletter.2up.ps > even.ps [RET]
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.
$ psbook input.ps > temp1.ps [RET] ...processing messages... $ psnup -l -pletter -2 -s.7 temp1.ps > temp2.ps [RET] ...processing messages... $ pstops "2:0(1in,0in)" temp2.ps > odd.ps [RET] ...processing messages... $ pstops "2:-1(1in,0in)" test2.ps > even.ps [RET] ...processing messages... $
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.
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.
$ ps2pdf sutra.ps sutra.pdf [RET]
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
gs to output the installed version.
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.
$ ps2ascii sutra.ps sutra.txt [RET]
This command writes a text file called `sutra.txt'. The original file, `sutra.ps', is not altered.
[<--] [Cover] [Table of Contents] [Concept Index] [Program Index] [-->]