< Day Day Up > |
Hack 39 Print to PDF with Ghostscript and RedMon on Windows
Enjoy a convenient path to PDF, free of charge . Any program that prints can also create PDFs. Adobe Acrobat sets the standard for PDF creation, but it can be too expensive. Ghostscript is a free PostScript interpreter that can also create PDFs, much like Acrobat's Distiller. Use RedMon to plug the power of Ghostscript into the convenience of a Windows printer, and you'll have "Print to PDF"!
4.9.1 Download and Install GhostscriptThe Ghostscript home page is http://www.cs.wisc.edu/~ghost/. As of this writing, the current version of AFPL Ghostscript is 8.14. Download and run the corresponding installer, gs814w32.exe . Our configuration, which follows , assumes Ghostscript is installed in the default location, C:\gs\ . If you ever need to reinstall Ghostscript, first uninstall it from the Add or Remove Programs dialog in the Windows Control Panel. 4.9.2 Download and Install RedMonThe RedMon home page is http://www.cs.wisc.edu/~ghost/redmon/. As of this writing, the current version of RedMon is 1.7. Download the corresponding zip file, redmon17.zip , into a new directory called redmon17 . Unzip it and double-click setup.exe to install. 4.9.3 Download and Unpack Our Virtual Printer KitThe PDF Hacks Virtual Printer Kit (VPK) has printer driver files, PPD files, and sample configuration files. Download it from http://www.pdfhacks.com/virtual_printer/. Unzip it into a convenient directory and note its contents. We'll call on these pieces as we need them. The README file might contain updates to these instructions.
The rest of this hack is divided by platform: Windows XP or 2000, and Windows 98. 4.9.4 Install and Configure a PDF Printer: Windows XP, 2000You already installed Ghostscript, RedMon, and our Virtual Printer Kit, right? All that remains is to install and configure your PDF printer. 4.9.4.1 Install a Virtual PostScript printerAny number of PostScript (PS) printers can use the same, core PS driver. To create a complete printer driver, we must combine this core with a printer's PPD file, which describes its capabilities in detail. Windows XP comes with an up-to-date core PS driver. Our Virtual PostScript Printer driver is simply an INF file instructing Windows to combine this core with the ( freely distributable) PPD from Adobe that describes the Acrobat 5 Distiller printer. The result is a printer that is almost ready to create a PDF.
The GS Pdf Printer printer should now appear in your Printers and Faxes folder. 4.9.4.2 Configure the RedMon redirected port to print PDFNow, wire your new printer to the Ghostscript program by configuring the redirected port you created, RPTPDF :.
Figure 4-8. RedMon passing the PostScript created by your printer driver to GhostscriptTo complete the port configuration, you must create the file C:\gs\pdf_printer.cfg , referenced earlier. It is a text file of additional arguments passed to Ghostscript. An example is included with our Virtual Printer Kit. Change the paths to suit your Ghostscript and system setup. -dSAFER -dBATCH -dNOPAUSE -Ic:\gs\gs8.14\Resource -Ic:\gs\fonts -Ic:\gs\gs8.14\lib -sFONTPATH=c:\WINDOWS\FONTS -sDEVICE=pdfwrite -r1200 -c save pop Voil ! Now, let's test it. Jump down to Section 4.9.6, later in this hack. 4.9.5 Install and Configure a PDF Printer: Windows 98You already installed Ghostscript, RedMon, and our Virtual Printer Kit, right? All that remains is to install and configure your PDF printer. 4.9.5.1 Install our Virtual PostScript printerAny number of PostScript (PS) printers can use the same core PS driver. To create a complete printer driver, we must combine this core with a printer's PPD file, which describes its capabilities in detail. The trouble is, we need an up-to-date PS core. Search your computer hard drive for ADOBEPS4.DRV to see if a recent PS core is installed. If you find it, you will be able to copy our required files, listed later in this section, from your hard drive. If you don't find it, you have a couple options. One option is to use the Adobe PostScript driver installer, as described in the earlier note. However, its license severely restricts its use. The other option is to download a printer driver from some manufacturer, a driver that contains all the core files we need and employs a permissive license. For this latter purpose, I like the printer driver download for the Phaser 550 (driver version 4.52) from http://www.Xerox.com. It is a self-extracting executable, win9xadb.exe , which provides all the necessary files in a neat directory. Check the Virtual Printer Kit README for other possible sources. Whichever driver you use, these are the files you ultimately must collect. You should collect them all from a single source to ensure they're compatible:
Copy these files into the Virtual Printer Kit directory driver\Win9x\ . That directory already contains the final two ingredients : our Virtual PostScript Printer PPD file and the Windows INF file used by the Add Printer install wizard to tie everything together.
4.9.5.2 Add and configure the RedMon redirected portLet's wire your new GS Pdf Printer printer to the Ghostscript program with a RedMon redirected port.
To complete the port configuration, you must create the file pdf_printer.cfg , referenced earlier. It is a text file of additional arguments passed to Ghostscript. An example is included with the Virtual Printer Kit. Change the paths to suit your Ghostscript and system setup. -dSAFER -dBATCH -dNOPAUSE -I"c:\gs\gs8.14\Resource" -I"c:\gs\fonts" -I"c:\gs\gs8.14\lib" -sFONTPATH=c:\WINDOWS\FONTS -sDEVICE=pdfwrite -r1200 -c save pop Voil ! Now, let's test it. 4.9.6 Test Your GS Pdf PrinterOpen the GS Pdf Printer properties dialog, click the General tab, and click Print Test Page. After a pause, a dialog will open where you can enter the PDF's filename. Select a suitable filename and click OK. Note that it will overwrite a file without asking and that it does not automatically add the PDF extension to the filename. When it is done, open the PDF in Reader. How does it look? The next few hacks discuss how to tune Ghostscript for your purposes. If an error occurs or the PDF file isn't created, carefully double-check the printer configuration and consult the log file:
|
< Day Day Up > |