If you want to get a handle on printing under Unix, you should get to know Ghostscript. As mentioned before, most Unix programs that print generate PostScript output. Ghostscript is a PostScript interpreter that includes these features:
Bitmap rendering from PostScript code in several different output formats
PostScript file filtering
Reading and writing to PDF format
To get a feel for how Ghostscript works, run it with a file and no other arguments:
In addition to getting a preview window showing the first page of the file, you should also see this message back at your terminal window:
>>showpage, press <return> to continue<<
As the prompt suggests, pressing RETURN pages through the file. After reaching the final page, you get a GS> prompt; you may press CONTROL-D or CONTROL-C to exit.
There are several frontend programs, such as gv and ggv, that give a nicer interface to the Ghostscript preview. Whether you use one of these frontend programs or not, running a preview can verify that you have a valid PostScript file to begin with. This can go a long way in tracking down problems, especially if your print spooler also uses Ghostscript to rasterize images for the printer.
A full gs command line such as the one in Section 12.5.8 may seem a bit complicated, especially when it comes to device specification. However, it's not hard to gain enough familiarity to make use of Ghostscript's filtering capabilities.
Take a close look at the following command, which filters old.ps to create new.ps:
gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pswrite -sOutputFile=new.ps old.ps
The first four options are typical for filters that run with no user input. Here's what they specify:
-q Quiet mode; suppress any normal diagnostic output.
-dNOPAUSE Do not wait for the user to press RETURN after each page.
-dBATCH Terminate after interpreting all input.
-dSAFER Disallow file alteration capabilities (to avoid security problems).
The -dPARANOIDSAFER option disables file-read capabilities.
The next two options usually go hand-in-hand when creating an output file:
-sDEVICE=driver_name Use driver_name as the output driver. In this context, the term driver usually refers to a file format driver rather than a piece of code that manipulates devices, though there are exceptions (such as the x11 driver for the preview window). To see a list of drivers, run gs -help.
Some drivers require other command-line parameters to operate correctly. Two notable examples are the uniprint and ijs drivers. The uniprint driver comes with a number of .upp files (containing extra parameters) in the Ghostscript library directory. To use these settings, use @file.upp; for example:
gs @file.upp -q -dNOPAUSE -dBATCH -sOutputFile=out ...
-sOutputFile=file Write output to file (use - for standard output). If you ish to create one file per page of PostScript input, insert %d somewhere nto the name of file. Ghostscript substitutes the page number for %d.
Here are a few more useful things that you can do with Ghostscript:
To transform a PostScript file into a PDF file, use the pdfwrite driver (Ghostscript comes with a ps2pdf script that does essentially the same thing):
gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -sOutputFile=file.pdf file.ps
The pswrite driver (introduced in the previous section) is an effective way to make somewhat defective files print. If you can view the file with Ghostscript, the chances are good that a file filtered with the pswrite driver will print on even a finicky printer.
You can combine several PostScript or PDF files into one by adding the additional filenames to the end of the command line.
To change the output resolution (in dots per inch), use the -rdpi or -rxdpixydpi parameters. The default resolution is usually 72 dpi. These commands generate larger bitmaps:
gs -q -dNOPAUSE -dBATCH -dSAFER -r150 -sDEVICE=pnmraw -sOutputFile=- file.ps gs -q -dNOPAUSE -dBATCH -dSAFER -r300x150 -sDEVICE=pnmraw -sOutputFile=- file.ps
If you have an inkjet or non-PostScript laser printer made by HP, then you almost certainly need the HPIJS (HP Inkjet Server) printer driver package. The main part of HPIJS is a program called hpijs. You can think of this as a plug-in driver for Ghostscript that translates Ghostscript's internal raster image format into printer formats. This driver is especially important if you are printing photographs or other graphics.
You can tell if you need HPIJS by looking at the PPD file for your printer. If you see -sDEVICE=ijs in the FoomaticRIPCommandLine parameter, you need the driver. You can install it as a binary package or from source code; the only thing that matters is that Ghostscript can find the command in its path.
Current versions of hpijs come with foomatic-rip and a set of PPD files. The best output quality likely comes from using these PPD files rather than random ones you see on the Internet.