Chapter 4. Creating PDF and Other Editions

Introduction: Hacks #32-50

There are lots of different ways to create PDF files, from simple printing to PDF, to macros, to tools built into various applications. After putting the effort into creating your source document, choose a pathway to PDF that produces exactly what you expect. Some ways of creating PDF are simple, and some are more involved.

Tip

Some applications, including many applications from Adobe, let you save files as PDF directly. This doesn’t require much hacking and so isn’t covered here, but it might be worth checking to see if there’s an easy path to PDF built into your application (e.g., File Save a Copy... Save as Type: PDF in Adobe Illustrator).

Create Interactive PDF with Your Word Processor

Interactive PDFs take advantage of the information in word processing documents to create navigation features such as bookmarks and hyperlinks.

Printing a document to create its PDF edition is common practice. It works beautifully, but it also leaves much behind. Document headings could have been turned into an outline of PDF bookmarks, and document links could have become live PDF links. Adding these features, shown in Figure 4-1, will help ensure that your readers have the best possible reading experience.

Automatically adding PDF navigation features from your document’s styles
Figure 4-1. Automatically adding PDF navigation features from your document’s styles

The trick to creating an interactive PDF from your source document is to use PDF tools that understand your document’s styles [Hack #24] . Such tools typically integrate with your word processor.

Warning

On Mac OS X, you can Save As PDF [Hack #40] from any application. That’s a quick way to get PDF, but it doesn’t create PDF navigation features that the methods described in this hack produce.

Microsoft Word and Adobe Acrobat’s PDFMaker

During setup, Adobe Acrobat gives you the option to install its PDFMaker macro for Word. PDFMaker adds a menu to Word called Adobe PDF (Acrobat 6) or Acrobat (Acrobat 5). It also adds a toolbar with buttons that activate items from this menu. Select Adobe PDF Convert to Adobe PDF or click the toolbar button (

image with no caption

) to create your PDF. On the Macintosh, Acrobat installs only the toolbar, with no extra menus, providing very little control over its operation.

On Windows, configure PDFMaker by selecting Adobe PDF Change Conversion Settings . . . from inside Word. The Conversion Settings drop-down box enables you to select a Distiller profile [Hack #38] , just as you would if you were printing a PDF. The remaining tabs enable you to add encryption, links, metadata, bookmarks, and other nifty features to your PDF. One feature I specifically disable is Enable Accessibility and Reflow with Tagged PDF (Acrobat 6) or Embed Tags in PDF (Acrobat 5). This feature allows PDF to behave somewhat like HTML, but it can double (or more!) your PDF’s file size. If you require HTML-like features, I recommend distributing an HTML edition [Hack #35] alongside your PDF edition.

Warning

When creating a PDF with a custom page size using PDFMaker, your links might end up in the wrong place on the page. As a workaround, try using a larger, standard page size with larger page margins. Create your PDF and then crop it down [Hack #59] to your custom page size in Acrobat.

Adobe offers various solutions for shifted PDF links at http://www.adobe.com/support/techdocs/19702.htm.

Microsoft Word and GhostWord on Windows

GhostWord is a Ghostscript interface that integrates with Word. It adds a toolbar button to Word that launches the GhostWord GUI, shown in Figure 4-2. Use the GUI to convert the currently active Word document to full-featured PDF. You can also run the GUI outside of Word. GhostWord even has a command-line interface.

Managing PDF feature settings and Ghostscript PDF creation settings from the GhostWord GUI
Figure 4-2. Managing PDF feature settings and Ghostscript PDF creation settings from the GhostWord GUI

GhostWord can add bookmarks, links, metadata, and display settings to your PDF. It also manages your Ghostscript settings. Select a hardcoded Ghostscript profile from the Document Optimize PDF for: drop-down box, or tweak Ghostscript settings individually under the Converter Settings tab. Save these settings to a configuration file for later retrieval.

GhostWord is distributed free of charge from http://www.et.dtu.dk/software/ghostword/.

Tip

GhostWord, along with the Gs4Word, PDF Tweaker, and extendedPDF macros, all require Ghostscript, a free program that works like Adobe’s Distiller. To install Ghostscript, see [Hack #39] .

Microsoft Word and Gs4Word on Windows

Gs4Word is a Word macro that interfaces with Ghostscript. It adds a menu to Word called PDF and a shortcut button to Word’s Standard toolbar. It can add bookmarks, metadata, and display setting to your PDF. Its configuration dialog enables you to manage a set of Ghostscript profiles. Set your desired profile with the PDF Configure . . . PDF File Output Medium drop-down box.

The Gs4Word home page (http://www.schmitz-huebsch.net/gs4word/) is in German, but you can configure the program’s interface to use English.

Sun StarOffice, OpenOffice, and extendedPDF

Newer versions of OpenOffice can create PDFs directly from your document with the File Export as PDF feature. However, the resulting PDF lacks interactive features.To create a PDF with bookmarks, metadata, and hyperlinks, you must use the extendedPDF macro in combination with Ghostscript or Distiller. Visit http://www.jdisoftware.co.uk/pages/epdf-home.php to learn more about extendedPDF.

Corel WordPerfect and PDF Tweaker

Newer versions of Corel WordPerfect have a File Publish To PDF feature that gives you options for adding PDF features. Or, you can use the PDF Tweaker macro for WordPerfect, which also adds links and bookmarks to your PDF. In addition to PDF Tweaker, you must also have Acrobat Distiller or Ghostscript. PDF Tweaker does not actually create the PDF; it just adds pdfmarks to the print job.

Visit http://www.wpuniverse.com/vb/showthread.php?threadid=6136 to learn more about PDF Tweaker.

Create a Printable, On-Screen Edition from Word

Change a few page settings to yield two-column, screen-oriented pages.

Most documents are configured to print letter-size pages with a vertical, portrait orientation. Yet computer screens have a horizontal, landscape orientation. Accommodate on-screen reading and paper printing by setting your document’s layout to two-column, landscape-oriented pages, producing the result in Figure 4-3. Sadly, Acrobat’s PDFMaker can’t create accurate bookmarks and hyperlinks in this kind of document.

A landscape orientation, which is better suited for on-screen reading
Figure 4-3. A landscape orientation, which is better suited for on-screen reading

Microsoft Word 2002

Select File Page Setup Margins. Set Apply To: to Whole Document. Set the Multiple Pages field to 2 Pages per Sheet. Set the Orientation to Landscape. Set the page margins to:

Top: 0.75 inch

Bottom: 0.75 inch

Outside: 0.50 inch

Inside: 0.50 inch

Click the Paper tab and set the Paper Size: to Letter. Click the Layout tab and set both Header and Footer to 0.40 inch. Click OK to accept these new Page Setup settings.

When you use the print preview, it will show you only one side of your “2-up” page. Print to PDF and review the results.

Microsoft Word 2000

Select File Page Setup Margins. Set Apply To: to Whole Document. Check the 2 Pages per Sheet checkbox. Set both Header and Footer to 0.40 inch. Set the page margins to:

Top: 0.75 inch

Bottom: 0.75 inch

Outside: 0.50 inch

Inside: 0.50 inch

Click the Paper Size tab. Set the Paper Size: to Letter and the Orientation to Landscape. Click OK to accept these new Page Setup settings.

When you use the print preview, it will show you only one side of your “2-up” page. Print to PDF and review the results.

Microsoft Word:Mac v.X (or any Mac application)

On the Macintosh, you don’t need to make changes to the document in Word, because the operating system offers a range of pages per sheet on the Layout area of the Print dialog box. Format the document as you normally would, and when you go to print to PDF, select the Layout option. You can pick from 1 to 16 pages on a sheet, though 2 is probably best if you want people to read it on-screen. Again, you won’t have all the features that PDFMaker provides.

Multipurpose PDF

Give readers many editions in one package without tagging your PDF.

PDF makes a document portable by wrapping all its resources into a neat, single package. As people desire more features, more things get packed into the PDF. By attempting to make one file do all things for all people, that one file becomes large and unwieldy. Its portability begins to suffer.

In particular, Adobe has worked to add an information-oriented XML-ish layer on top of its presentation-oriented PDF features. The result is a single file that you can use for many purposes, such as paper printing, handheld reading, accurate text-to-speech, and accurate data extraction. However, creating these tagged PDFs is a slow and expensive process. The data layer is interwoven with the presentation layer, so accessing the data is difficult. Consequently, your readers have few options for utilizing this data. Finally, a tagged PDF file can grow to more than twice the size of its untagged counterpart.

In general, I advocate distributing a separate edition for each target medium. This is much easier on your readers and on your workflow. Eating sushi requires two chopsticks. Planar geometry requires five postulates. Some things shouldn’t be reduced too far; don’t feel compelled to make one edition do all things for all readers.

Tools, Not Rules

With that said, sometimes it makes sense to distribute multiple editions as a single PDF. For example, you might want to use PDF features such as encryption or digital signatures across all your editions. Instead of tagging your PDF, consider packing alternative editions into your PDF as attachments [Hack #54] .

Tip

Candidates for attachments include the HTML edition [Hack #36] , spreadsheet-ready document data [Hack #55] , the handheld edition [Hack #36] , or even the source document.

The concept of different attachments for different purposes makes more sense to readers than a single, shape-shifting (tagged) PDF. Also, they will immediately understand the benefits of each alternative edition. “HTML Edition” means reflowing text, easy data extraction, and easy text-to-speech. “Tagged PDF” means little to most people, so you might add: " . . . that acts like HTML sometimes. You own Acrobat, right?” You will have a struggle on your hands, assuming your reader has that much patience.

Create an HTML Edition from Your Word Processor

Offer readers both PDF and HTML editions of your work and they will love you.

PDF is the ideal medium for preserving your document’s look. HTML is a better choice for distributing your document’s data. Your source document can give you both, as shown in Figure 4-4.

Different editions for different purposes; let readers decide
Figure 4-4. Different editions for different purposes; let readers decide

PDF does have newer features for tagging document data, allowing it to behave somewhat like HTML. However, PDF tagging can double your file size. Also, only a few, proprietary programs are able to tease the tagged data out of a PDF. Consider attaching alternative editions or even attaching the source document to your PDF [Hack #54] instead of tagging.

Create an HTML Edition from Microsoft Word 2002 and 2003

In Word 2002 and 2003 you can save your document as a web page or a filtered web page. A Word web page includes extra document information in case you want to edit it in Word later. A filtered web page omits this extra information, making it more suitable for distribution.

  1. If you have been making changes, save your source document now (File Save). Otherwise, your changes will be lost.

  2. Select File Save As . . . .

  3. In the “Save as type” drop-down box, select Web Page, Filtered.

  4. A dialog will open, warning you that this format doesn’t contain Word’s special tags. Confirm that this is acceptable by clicking Yes.

  5. The side effect of this Save As . . . operation is that you are no longer editing the source document in Word. Instead, you are editing the filtered HTML document you just created. Close this document, because you should make edits only to the source.

Customize HTML output options by selecting Tools Options . . . General Web Options . . . . For example, you can enable old-fashioned HTML 3.2 text styling by disabling Rely on CSS for Font Formatting.

Create an HTML Edition from Microsoft Word 2000

Word 2000 does not have a built-in Save As Filtered Web Page option. You must download and install the Office 2000 HTML Filter 2.0 component from Microsoft:

http://www.microsoft.com/downloads/details.aspx?FamilyID=209ADBEE-3FBD-482C-83B0-96FB79B74DED

This adds an Export to Compact HTML feature to Word 2000. It also includes a standalone program for filtering Word’s special tags out of existing HTML.

From Word, select File Export To Compact HTML . . . . After you create the HTML, your source document remains open in Word (unlike using Save As . . . in Word 2002, as noted earlier).

Customize HTML output options by selecting Tools Options . . . General Web Options . . . . For example, you can enable HTML 3.2 text styling by unchecking the Rely on CSS for Font Formatting checkbox.

Create an HTML Edition from Microsoft Word:Mac v.X

Word:Mac does not have a built-in Save As Filtered Web Page option, but it does include a Save Only Display Information option under File Save As Web Page that accomplishes a similar result. The Web Options button on that dialog also enables you to choose how some aspects of web page creation are handled.

Convert Word Documents to HTML with wvWare

wvWare can convert Microsoft Word documents to several formats, including HTML. It is a command-line tool developed on Linux that has been ported to Windows. It is free software and can be found at http://wvware.sourceforge.net.

Create an HTML Edition from StarOffice and OpenOffice

Like Word 2002, StarOffice enables you to Save As . . . HTML, but it then replaces the currently open source document with the new HTML document. Close this new document because you should edit only the source.

Customize HTML output options from Tools Options . . . Load/Save, especially the HTML Compatibility section. I like to set the HTML Compatibility Export to HTML 3.2 when creating material for handheld reading.

Create a Handheld Edition from Your HTML

Deliver your content to mobile professionals and gadget geeks without PDF’s overhead.

PDF is wonderful stuff—otherwise, you wouldn’t likely be reading this book—but there are times when it’s not the right tool for the job. If you need to distribute information to readers using handheld devices such as Palms and Pocket PCs, you should take a look at Plucker.

Palm OS Reading with Plucker

Plucker is a toolset for reading HTML documents on Palm OS devices. Plucker Distiller prepares your HTML and packs it into a Palm PDB file. Plucker Desktop is a graphical interface for managing Distiller. Plucker Viewer, shown in Figure 4-5, organizes Plucker documents on your Palm so that you can read them. Desktop and Distiller run on your host machine, while the Viewer runs on your Palm. Plucker is free software.

Mobilizing your document
Figure 4-5. Mobilizing your document

Visit http://www.plkr.org and download the Plucker Desktop installer for your platform. Launch the installer and it will unpack all three components. You must supply information about your target Palm device, but do not worry about getting locked into these preferences. You can configure document conversion settings individually later.

Tip

If the Plucker Desktop gives you regular errors that the locale cannot be set, select Options Preferences Interface and uncheck the “Translate interface into the local language” checkbox.

Plucker Desktop organizes local files and remote web pages into channels. To create a channel for your HTML file, drag-and-drop it into Plucker Desktop. After you name the new channel, its configuration window opens. Here are a few items of particular interest:

Limits

For converting a traditional document (as opposed to a web site), increase the Maximum Depth to ensure that all your links get followed. Set Stay on Host to keep Plucker from following any Internet references.

Images

Images can quickly bloat your document file size. Tune these settings to match your document’s requirements.

Under Advanced Image Handling you can set the maximum dimensions for image thumbnails. Any image larger than this gets downsampled to fit. Thumbnails are displayed inline with your document and can be linked to a larger image.

The original, standard Palm OS display is 160 160, so thumbnails shouldn’t be wider than 150 pixels on these models (to leave room for the scrollbar). The newer, high-resolution display is 320 320, which can accommodate a 300-pixel-wide thumbnail. Using the smaller, 150-pixel width ensures your images are fully visible on all Palm OS devices. The viewer trims thumbnails that are too wide to fit on the screen. When fidelity is essential, use the other settings in this window to link the thumbnail to a larger image that the user can pan.

Tip

High-resolution Palm OS devices should use the “hires” versions of the viewer and SysZLib library.

Output Options

ZLib compression works much better than DOC compression does. To read ZLib-compressed documents you must run Palm OS 3 or later (OS 3 premiered in 1998 on the Palm III) and have the SysZLib shared library installed on the device. SysZLib comes packaged with Plucker Desktop.

Destination

Specify the location where the output document will be put.

Create the Plucker document by selecting the channel and then selecting Update Update Selected Channels.

Tip

Preview your Plucker documents on your PC by installing the Palm OS 5 Simulator. Download it from http://www.palmos.com/dev/tools/simulator/.

For best results, the input should use old-fashioned HTML 3.2 text-styling tags (e.g., <font>) instead of CSS styling. [Hack #35] discusses how to set your word processor for HTML 3.2 output.

Plucker for Pocket PC

As of this writing, a Pocket PC reader for Plucker files is under development at http://vade-mecum.sourceforge.net. Microsoft provides a Pocket PC emulator you can use to test it. Download Embedded Visual Tools (EVT) from:

http://www.microsoft.com/downloads/details.aspx?FamilyId=F663BF48-31EE-4CBE-AAC5-0AFFD5FB27DD

When installing EVT, use the following CD Key, which is provided by the documentation:

TRT7H-KD36T-FRH8D-6QH8P-VFJHQ

Choose to install the Pocket PC SDK, or run the PocketPC_2002_SDK.exe setup program (which was unpacked by the EVT installer). Start the emulator by launching CEFILEVW.EXE and opening a connection.

Convert Documents from Tools You Don’t Own to PDF

Even if you don’t have the document’s authoring tool, you can often convert it to a PDF file.

With the wide variety of authoring tools people use, it is easy to find yourself with a document you can’t open and read. Here are some freely available document viewers. Open your trouble document and then print it to PDF.

Microsoft Office Viewers

Microsoft provides freely distributable, Windows-based document viewers for its Office suite. Download the viewer you need from:

http://office.microsoft.com/assistance/preview.aspx?AssetID=HA010449811033

Install the viewer, open your document, and then print to Acrobat Distiller. If you don’t have Acrobat, use our GS Pdf Printer [Hack #39] , instead.

Tip

OpenOffice (http://www.openoffice.org) is a free authoring suite that can open a variety of file formats, including Microsoft Word, Excel and PowerPoint. It also includes a built-in Export as PDF feature. Use it to convert your Microsoft Office files to PDF.

Corel WordPerfect Viewer

The Microsoft Word Viewer, referenced earlier, can also open WordPerfect files. You must first install the Microsoft Office Converter Pack.

Download the Office 2003 Resource Kit (ork.exe) from http://www.microsoft.com/office/ork/2003/tools/BoxA07.htm. Install ork.exe, and it will unpack the Microsoft Office Converter Pack installer (oconvpck.exe). While ork.exe does not run on Windows 98, oconvpck.exe (which is really all we want) does. Search your disk for oconvpck.exe and install it.

After installing the Office Converter Pack, the Word Viewer Open dialog still won’t see WordPerfect WPD files. You’ll need to drag-and-drop, type the full name, or change WPD file extensions to DOC. This last choice could end up confusing people down the road.

Once it’s open, print the document to Acrobat Distiller or the GS PDF Printer [Hack #39] .

Online Conversion

Adobe offers an online service for creating PDFs from your source documents. It accepts Microsoft Office and Corel WordPerfect documents. It also accepts Adobe Illustrator, InDesign, FrameMaker, PageMaker, and Photoshop files. Visit https://createpdf.adobe.com to learn more.

Acrobat Distiller and Its Profiles

Select the best Distiller profile for your purpose.

When you use Acrobat’s “Print to PDF” or use the PDFMaker macro for Word, Adobe’s Distiller is the engine that creates your PDF. What kind of PDF do you need? You can configure Distiller to create the best PDF for your purpose. The choice is usually between document fidelity and file size. File size becomes an issue only when distributing a PDF electronically. When in doubt, choose fidelity.

Changing the Distiller Profile

Acrobat Distiller comes with a few preconfigured profiles. They are also called Settings or joboptions files. When printing to PDF, change the profile by clicking the Print dialog’s Properties button (Windows), or by selecting PDF Options from the drop-down box that starts out saying Copies & Pages (Mac). Select the Adobe PDF Settings tab and select a Distiller profile from the Default Settings: (Acrobat 6) or Conversion Settings: (Acrobat 5) drop-down box. This choice is not permanent. To change the default profile, consult the Adobe PDF (Acrobat 6) or Acrobat Distiller (Acrobat 5) printer properties.

When using PDFMaker on Windows, change its profile inside Word by selecting Adobe PDF Change Conversion Settings . . . (Acrobat 6) or Acrobat Change Conversion Settings . . . (Acrobat 5). This choice, shown in Figure 4-6, becomes the default.

Distiller settings, which you use whenever you create PDFs using Acrobat
Figure 4-6. Distiller settings, which you use whenever you create PDFs using Acrobat

When creating a PDF for a print shop or service bureau, ask them for a joboptions file to use. On Windows, move it to Distiller’s Settings folder, which is located somewhere such as C:\Program Files\Adobe\Acrobat 5.0\Distillr\Settings\. On the Macintosh, open Distiller and use the Settings Add Adobe PDF Settings . . . menu option to add it to the list. Then, select the print shop or service bureau’s profile when creating your PDF, as described earlier.

Stock Distiller Profiles, Side by Side

Each profile that comes with Acrobat has subtle differences. We highlight only the big differences in Tables Table 4-1 and Table 4-2 because they have the greatest effect on your PDF.

Table 4-1. Acrobat 6 Distiller profiles

Smallest File Size

Standard

High Quality and Press Quality

Color Image Resolution (dpi)

100

150

300

Gray Image Resolution (dpi)

150

150

300

Mono Image Resolution (dpi)

300

300

1200

Compressed Image Fidelity

Low

Medium

Maximum

Embedded Fonts

None

[1]

All

[1] All fonts are embedded except Base 14 fonts and these Windows system fonts: Century Gothic, Georgia, Impact, Lucida Console, Tahoma, Trebuchet, and Verdana.

Table 4-2. Acrobat 5 Distiller profiles

Screen

eBook

Print

Press

Color Image Resolution (dpi)

72

150

300

300

Gray Image Resolution (dpi)

72

150

300

300

Mono Image Resolution (dpi)

300

300

1200

1200

Compressed Image Fidelity

Medium

Medium

High

Maximum

Embedded Fonts

None

All Except Base 14

All

All

A 150 dpi image is usually appropriate for printing on a 600 dpi black-and-white laser or inkjet printer. So, the Standard profile (Acrobat 6) seems to suit most purposes. Color printers can take advantage of higher image resolutions. Visit http://www.scantips.com/basics03.html to discover the principles of printer arithmetic.

In Acrobat 5, the eBook profile serves most purposes; it resembles the Standard profile very closely. Who would have guessed that?

Tip

When distilling a document containing mostly screenshot images, try using the ZIP image compression filter instead of JPEG. In Distiller 5, you can also try the 4-bit and 8-bit quality settings. Not only does this yield superior screenshot compression, but you also get superior images. See [Hack #42] to learn how to alter Distiller profiles. These compression settings are under the profile’s Images tab (Acrobat 6) or Compression tab (Acrobat 5)

If your readers will be downloading files from the Web or receiving them through email, using the Smallest File Size (Acrobat 6) or Screen (Acrobat 5) profile will ensure that low-bandwidth users aren’t clobbered with long PDF downloads. On the other hand, if you’re sending files to a printer and want the best results possible, you’ll want to use the Press Quality profile, which yields the highest-fidelity PDF.

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”!

Tip

For a prepackaged Ghostscript/RedMon installer, try PDFCreator (http://sourceforge.net/projects/pdfcreator/) or PrimoPDF (http://www.primopdf.com).

Download and Install Ghostscript

The 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.

Download and Install RedMon

The 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.

Download and Unpack Our Virtual Printer Kit

The 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.

Tip

You can download a PostScript driver installer for Windows from the Adobe web site. However, its license suggests that you can use it only in conjunction with other Adobe products, such as a PostScript printer. Review this license. If it suits you, download the latest installer (currently 1.0.6) from http://www.adobe.com/support/downloads/product.jsp?product=44&platform=Windows

You can use the ADIST5.PPD printer description from the Virtual Printer Kit during setup to create a GS Pdf Printer. Continue with Section 4.9.5.2.

The rest of this hack is divided by platform: Windows XP or 2000, and Windows 98.

Install and Configure a PDF Printer: Windows XP, 2000

You already installed Ghostscript, RedMon, and our Virtual Printer Kit, right? All that remains is to install and configure your PDF printer.

Install a Virtual PostScript printer

Any 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.

  1. From the Printers and Faxes folder (Start Settings Printers and Faxes) click Add a Printer under Printer Tasks and the wizard will open. Click Next to begin.

  2. Select Local Printer, uncheck Automatically Detect, and click Next.

  3. Select Create a New Port and choose the Redirected Port from the drop-down list. Click Next. A dialog will open asking for the port name. Enter RPTPDF: and click OK. When you installed RedMon, it created this Redirected Port option.

  4. The wizard will present you with a list of printers and manufacturers, but we don’t want these. Click Have Disk . . . and then Browse . . . . Navigate to the driver\WinXP\ directory in our Virtual Printer Kit, open ADIST5GS.INF, and then click OK. The wizard should now display only one printer, our Virtual PostScript Printer. Select this printer, as shown in Figure 4-7. Windows might complain that this printer driver is not signed. Click Next.

    Our Virtual PostScript Printer driver, which has the exact same printer profile as Acrobat’s PDF printer
    Figure 4-7. Our Virtual PostScript Printer driver, which has the exact same printer profile as Acrobat’s PDF printer
  5. If the wizard remarks that a driver already is installed for this printer, select Keep Existing Driver and click Next.

  6. Name the printer GS Pdf Printer and select No default printer. Click Next.

  7. Select No to keep it from printing a test page and click Next.

  8. Click Finish to complete the installation. Windows might complain that our driver is not Windows Logo-certified. If so, confirm that you want to install our driver.

The GS Pdf Printer printer should now appear in your Printers and Faxes folder.

Configure the RedMon redirected port to print PDF

Now, wire your new printer to the Ghostscript program by configuring the redirected port you created, RPTPDF:.

  1. Right-click your new GS Pdf Printer printer and select Properties. Click the Ports tab.

  2. Make sure the “Enable bidirectional support” checkbox is unchecked.

  3. Select the Redirected Port you just created, RPTPDF:, and click Configure Port . . . .

  4. Set the port properties as shown in Table 4-3, changing the paths to suit your setup. Be careful not to overlook the solitary hyphen at the end of the program arguments.

    Table 4-3. RedMon port properties

    Field

    Value

    Redirect this port to the program:

                                           
                                              C:\gs\gs8.14
                                           
                                           \bin\gswin32c.exe

    Arguments for this program are:

    -sOutputFile="%1"@
                                           
                                              C:\gs
                                           
                                           \pdf_printer.cfg-f -

    Output:

    Prompt for Filename

    Run:

    Minimized

  5. Click the Log File button to configure the Log File Properties. Set Use Log File and enter a log filename, such as C:\gs\pdf_printer.log. Don’t set Debug.

  6. Click OK to close the Log File Properties. Click OK to accept the new port settings. Click Close to accept the new printer settings, as shown in Figure 4-8, and close the GS Pdf Printer Properties dialog.

RedMon passing the PostScript created by your printer driver to Ghostscript
Figure 4-8. RedMon passing the PostScript created by your printer driver to Ghostscript

To 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.

Install and Configure a PDF Printer: Windows 98

You already installed Ghostscript, RedMon, and our Virtual Printer Kit, right? All that remains is to install and configure your PDF printer.

Install our Virtual PostScript printer

Any 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:

ADOBEPS4.DRV
ADOBEPS4.HLP
ADFONTS.MFM
ICONLIB.DLL
PSMON.DLL

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.

  1. From the Printers folder (Start Settings Printers) double-click the Add Printer icon. Click Next to begin.

  2. Select Local Printer and click Next.

  3. The wizard will present you with a list of printers and manufacturers, but we don’t want these. Click Have Disk . . . and then Browse . . . . Navigate to the driver\Win9x\ directory in our Virtual Printer Kit and click Open and then OK. The wizard should now display only one printer, our Virtual PostScript Printer. Select this printer. Click Next.

  4. If the wizard remarks that a driver is installed for this printer, select Replace Existing Driver and click Next.

  5. Under Available Ports, select FILE: and click Next.

  6. Name the printer GS Pdf Printer and select No default printer. Click Next.

  7. The wizard should be finished. If a Version Conflict dialog opens to complain that you are overwriting newer files with older files, the safest thing to do is to keep the newer files.

    The GS Pdf Printer printer now should appear in your Printers and Faxes folder. Wire your new printer to the Ghostscript program by adding and configuring a redirected port.

Add and configure the RedMon redirected port

Let’s wire your new GS Pdf Printer printer to the Ghostscript program with a RedMon redirected port.

  1. Right-click your new GS Pdf Printer printer and select Properties. Click the Details tab.

  2. Click Add Port . . . and a dialog opens. Select Other, select Redirected Port, and click OK. Name the port RPTPDF: and click OK.

  3. On the Details tab, click Spool Settings . . . . Select “Disable bi-directional support for this printer” and click OK.

  4. On the Details tab, click Port Settings . . . . Set the port properties as shown in Table 4-4, changing the paths to suit your Ghostscript setup. Be careful not to overlook the solitary hyphen at the end of the program arguments.

    Table 4-4. RedMon port properties

    Field

    Value

    Redirect this port to the program:

                                           
                                              C:\gs\gs8.14
                                           
                                           \bin\gswin32c.exe

    Arguments for this program are:

    -sOutputFile="%1"@"
                                           
                                              C:\gs
                                           
                                           \pdf_printer.cfg"-f -

    Output:

    Prompt for Filename

    Run:

    Minimized

  5. Click the Log File button to configure the Log File Properties. Set Use Log File and enter a log filename, such as C:\gs\pdf_printer.log. Don’t set Debug.

  6. Click OK to close the Log File Properties. Click OK to accept the new port settings. Click OK to accept the new printer settings and close the GS Pdf Printer Properties dialog.

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.

Test Your GS Pdf Printer

Open 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:

  • Is bi-directional printing disabled?

  • Does the redirected port setting match those given earlier? Mind the separate, trailing hyphen in the program arguments.

  • Is pdf_printer.cfg in the correct location? Do its contents match those given earlier?

  • Have all C:\gs\ paths been updated to reflect the location of your Ghostscript installation?

Save As PDF with Mac OS X

Create PDFs quickly and easily from any Macintosh OS X program.

Apple built a “Save As PDF” capability right into the Macintosh OS X Print dialog box. Any time you go to print a document, you can choose Save As PDF . . . from the bottom of the Print dialog box. Unfortunately, this approach provides no options and tends to produce large files, but at least it is a quick solution to producing PDFs. This option is available at the bottom left of any Print dialog box, as shown in Figure 4-9.

A Print dialog box with a Save As PDF . . . option
Figure 4-9. A Print dialog box with a Save As PDF . . . option

If you click the Save As PDF . . . button, a file dialog box will ask you where to put the resulting PDF file. Select a location, click OK, and the Mac will print to a PDF file.

The results are different from those created by Distiller. On an early draft of Chapter 1 of this book, without figures, Mac OS X produced a 344 KB file, while the PDFMaker macro produced a 144 KB file.

There aren’t any obvious configuration options for Save as PDF . . . , but if you have Mac OS X 10.3 or later, you can choose settings through the Filters tab of the ColorSync utility’s Preferences window. (The ColorSync utility is in MacintoshHD:Applications:Utilities.) If you check PDF Workflow in the Domains tab, you’ll be able to change your PDF options from the Print dialog box as well.

Maximize PDF Portability

PDF version differences can affect you and your readers.

To best serve your readers, you should ensure that your PDF is compatible with their viewers. What PDF viewers are they running? Assume that they have at least upgraded to the previous version of Acrobat/Reader (or another, compatible viewer). PDFs created with the newest Acrobat might be incompatible with previous versions. A little care can prevent inconveniences to your readers such as the one shown in Figure 4-10.

Messages that annoy readers
Figure 4-10. Messages that annoy readers

PDF Versions Overview

With each new version of Acrobat, Adobe introduces an updated version of the PDF specification. They go together, as shown in Table 4-5.

Table 4-5. Acrobat version information

Acrobat version

Year introduced

PDF version

3.0

1996

1.2

4.0

1999

1.3

5.0

2001

1.4

6.0

2003

1.5

In many cases, an older viewer still can read a newer-version PDF (although the viewer will complain). Its behavior depends on which new features the PDF uses. Which viewers implement newer features? Here are some highlights, selected for their bearing on mass distribution. For complete details, consult the PDF Reference, Versions 1.3, 1.4, and 1.5.

PDF 1.3 (Acrobat 4) introduced:
  • Digital signatures

  • File attachments

  • JavaScript support

  • Logical page numbering

PDF 1.4 (Acrobat 5) introduced:
  • Additional 128-bit encryption option

  • Additional JavaScript trigger events (document close, will save, did save, will print, did print)

  • Enhanced interactive forms

PDF 1.5 (Acrobat 6) introduced:
  • Additional file compression options

  • Additional encryption options

An older viewer can simply ignore many of the things it doesn’t understand. The showstoppers are the compression or encryption features, because the viewer can’t show the document if it can’t read the streams.

Tip

If your PDF relies on newer JavaScript or forms features to work properly, prevent older viewers from opening your PDF. Determine the minimum PDF version your document requires and then apply the corresponding encryption using an empty password [Hack #52] . Older viewers simply won’t be able to read it.

Create Compatible PDFs

Out of the box, Distiller or PDFMaker yields PDFs that are compatible with the previous version of Acrobat. No problem.

When you open a PDF in Acrobat, modify it, and then save it, your PDF’s version is upgraded silently to match Acrobat’s. It is no longer compatible with the previous versions of Acrobat/Reader. This happens regardless of whether your PDF uses any of the new features.

Tip

Install older versions of Acrobat Reader and test your PDFs, if you are worried about how they’ll look or function. Download old installers from http://www.adobe.com/products/acrobat/reader_archive.html or http://www.oldversion.com/program.php?n=acrobat.

One solution is to use the Reduce File Size feature in Acrobat 6 (File Reduce File Size . . . Compatible with: Acrobat 5.0 and later), which enables you to also set the compatibility level of the resulting PDF. Another solution is to use the PDF Optimizer feature (Advanced PDF Optimizer . . . ) and set the “Compatible with” field to “Acrobat 5.0 and later.” A third option is to refry your PDF [Hack #60] .

Configure Distiller and Ghostscript for Your Purpose

Unlock the secret powers of Distiller and Ghostscript.

Acrobat Distiller creates PDF based on its current profile setting [Hack #38] . On Windows, choose a profile when you print by changing the Print Properties . . . Adobe PDF Settings tab Default Settings drop-down box, as shown in Figure 4-11. On a Macintosh, choose PDF Options from the drop-down box that starts out saying Copies & Pages instead of selecting the Adobe PDF Settings tab. When using Ghostscript, you can reference a joboptions file in pdf_printer.cfg .

Choosing PDF printer properties
Figure 4-11. Choosing PDF printer properties

Whenever you print to an Acrobat PDF printer, you can select a profile that creates the best PDF for your purpose. You can view and edit these profiles using the graphical Distiller application. The surprise is that these profiles, or joboptions files, are plain-text PostScript snippets that give you more control over Distiller than the GUI does. They are also compatible with Ghostscript, although Ghostscript does not implement all the possible settings. Indeed, the joboptions file (and its specification) is a good place to get the straight dope on what Distiller and Ghostscript can really do.

Acrobat Distiller Parameters Tell the Full Story

To fully understand Distiller and Ghostscript features, you must read the Acrobat Distiller Parameters document from Adobe. It is also the definitive guide to joboptions file parameters.

If you have Acrobat on your computer, open Distiller and select Help Distiller Parameters Guide, or search your disk for distparm.pdf. On the Macintosh, this file is in the Extras folder on the installer CD. The Acrobat 6 version of distparm.pdf is not available online except to paying Adobe ASN Developer Program members. The next best thing is the Acrobat 5 version, which is bundled with the freely downloadable Acrobat 5 SDK:

http://partners.adobe.com/asn/acrobat/download.jsp

Ghostscript users should also read C:\gs\gs8.14\doc\Ps2pdf.htm or, online:

http://www.cs.wisc.edu/~ghost/doc/cvs/Ps2pdf.htm

If you plan to deliver PDF to a service bureau, find out if they have a joboptions file you should use when creating your PDF.

Distiller joboptions Profiles

Acrobat Distiller’s joboptions files are easy to view and modify using the Distiller GUI, as shown in Figure 4-12. Launch the Distiller application, and set Default Settings (Acrobat 6) or Job Options (Acrobat 5) to the profile you want to view or edit. Then, select Settings Edit Adobe PDF Settings (Acrobat 6) or Settings Job Options (Acrobat 5).

As noted earlier, this graphical interface does not give you access to all the settings documented in Acrobat Distiller Parameters. Because joboptions files are plain text, you can also view or edit them using a text editor.

The Distiller GUI: a nice place to view and change joboptions files
Figure 4-12. The Distiller GUI: a nice place to view and change joboptions files

Ghostscript joboptions Profiles

joboptions files are written in PostScript, so you can pass them to Ghostscript just before your input file using the -f option. Add a joboptions file to your GS Pdf Printer [Hack #39] by appending it to the end of the pdf_printer.cfg file you created, like so:

-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
-f c:\gs\pdfhacks.gs.joboptions

The file pdfhacks.gs.joboptions comes with our Virtual Printer Kit [Hack #39] . It is organized and commented to make parameters easy to read and understand. Open it in your text editor and take a look. Edit it to suit your needs. Parameters not supported by Ghostscript are commented out.

If you need to manage a collection of these profiles, consider creating one GS Pdf Printer for each profile. Each printer would have its own Redirected Port, each port using its own cfg file, each cfg file referencing its own joboptions file.

Embed and Subset Fonts to Your Advantage

Sometimes it makes sense to embed fonts, while other times it just costs you space.

An embedded font is a font that has been packed into your PDF file as a resource. Embedding ensures that your PDF text looks perfect wherever it is printed or viewed. Embedding also bulks up your PDF’s file size. In this hack we discuss embedding and its alternatives, their upsides and downsides. We also discuss font subsetting, which is the practice of embedding only a subset of the entire font. Subsetting was designed to reduce file size, but it can actually create bloat when misused.

Tip

See which PDF fonts are embedded or subset in your PDF by opening the PDF in Acrobat or Reader and selecting File Document Properties . . . Fonts. Embedded fonts will describe themselves as Embedded, whereas unembedded fonts will not — likewise for subset fonts.

Embedding Fonts into PDF

For most purposes, all fonts should be embedded. If a font is not embedded in your PDF, Acrobat/Reader will try to find it on the computer. If the font isn’t installed on the computer, Acrobat/Reader will try to approximate the font using its own resources, as shown in Figure 4-13. By not embedding a font, your PDF might end up looking slightly different on different machines.

Original fonts (top) approximated by Acrobat (bottom), when they are not embedded in the PDF and they are not available on the system
Figure 4-13. Original fonts (top) approximated by Acrobat (bottom), when they are not embedded in the PDF and they are not available on the system

Tip

How well does Acrobat/Reader approximate fonts? Turn off Use Local Fonts in Reader or Acrobat to see how your unembedded fonts might appear on other computers. Acrobat 6: Advanced Use Local Fonts. Reader 6: Document Use Local Fonts. Acrobat 5: View Use Local Fonts. Or, just Ctrl-Shift-Y.

The drawback to embedding is that each embedded font could add about 20 KB to your PDF file size. For some large PDFs this is negligible. For online PDFs of only a few pages, it can be unacceptable.

When PDF file size is critical, select some or all of your document fonts from one of the Base font collections and then configure Distiller to never embed them. The Base 14 fonts provide a solid core that is the safest to use without embedding. The Base 35 fonts provide traditional styles that are reasonably safe to use without embedding. For the fonts you must embed, prefer Type 1 fonts over TrueType fonts because embedded Type 1 fonts are much smaller.

The Base 14 Fonts

The Base 14 fonts are utilitarian fonts that you can use safely in any PDF without embedding. Their family names are Times, Helvetica, Courier, and Symbol. Times New Roman commonly is used instead of Times, and Arial commonly is used instead of Helvetica.

Tip

If your document uses Helvetica and you want to be sure your PDF is displayed using Helvetica (and not Arial), double-check to make sure it gets embedded. Some Distiller profiles [Hack #38] automatically exclude all Base 14 fonts from embedding.

Figure 4-14 provides samples of the Base 14 fonts, along with samples of the Base 35 fonts.

The Base 35 fonts: a superset of the Base 14 fonts (left column)
Figure 4-14. The Base 35 fonts: a superset of the Base 14 fonts (left column)

The Base 35 Fonts

The Base 35 fonts are a superset of the Base 14 fonts. They add style, and most of them are reasonably safe to use without embedding. If your system does not have one of these font families, shown in Table 4-6, try using a lookalike font instead.

Table 4-6. Base 35 font families and common lookalikes that are reasonably safe to use without embedding

Font family name

Common lookalike

Times

Times New Roman

Helvetica

Arial

Helvetica Narrow

Arial Narrow

Palatino

Book Antiqua

Bookman

Bookman Old Style

Avant Garde

Century Gothic

New Century Schoolbook

Century Schoolbook

Courier

Courier New

Symbol

Symbol MT

If you use the Base 35 fonts shown in Table 4-7, you should embed them. Any decorative or stylized font always should be embedded.

Table 4-7. Base 35 font families you should embed

Font family name

Common lookalike

Zapf Dingbats

Monotype Sorts

Zapf Chancery

Monotype Corsiva

If the Base 35 fonts shown in Figure 4-14.

Configure Distiller Font Embedding

The Fonts tab in your Distiller Job Options setting is the place to control font embedding, as shown in Figure 4-15. The Embed All Fonts checkbox sets the default policy. Unchecking it means Embed No Fonts. The Never Embed and Always Embed font lists are used to override the default policy on a font-by-font basis. So, if Embed All Fonts is checked, all document fonts get embedded in the PDF except those listed under Never Embed. If Embed All Fonts is unchecked, only the document fonts listed under Always Embed get embedded in the PDF.

Changing font settings using the Distiller Fonts tab
Figure 4-15. Changing font settings using the Distiller Fonts tab

Configure Distiller to never embed Base 14 fonts by putting them (and their lookalikes) on the Never Embed list. Give the Base 35 fonts (and their lookalikes) the same treatment if you desire. When using Acrobat/Distiller 5.0, the Base 14 fonts do not automatically include their lookalikes. On Windows, change the Font Source drop-down box to C:\windows\fonts or C:\winnt\fonts in order to see a list of your system fonts, which is where you’ll find the lookalike fonts.

Tip

Acrobat 6 enables you to remove embedded fonts from your PDF using its PDF Optimizer feature. Select Advanced PDF Optimizer . . . Fonts to select fonts for removal.

Configure Ghostscript Font Embedding

Ghostscript must embed all fonts except the Base 14 fonts. You can embed these, too, if you choose. Asking Ghostscript to withhold embedding of any other font could yield a PDF that doesn’t work properly in Acrobat and Reader. Perhaps a future version of Ghostscript will resolve this issue.

Subset Embedded Fonts

It does not make sense to pack an entire font into a PDF when only a few characters from that font are actually used. Font subsetting is the technique of embedding only a portion of a font. A font subset contains only the characters used in your document. The alternative is to pack the entire font into the PDF. Distiller can entirely pack only Type 1 fonts into a PDF. Distiller subsets fonts in any other format (e.g., TrueType).

For most purposes, all embedded fonts should be subset. It only becomes an issue later, when assembling many PDF pieces into a single PDF. If each PDF piece uses embedded subset fonts, the resulting final document is in danger of having a single font represented by many unnecessary subsets. This can severely bloat the final document file size.

One solution to subset bloat is to use Acrobat 6 for assembling your document. After assembly, Save As . . . to a new PDF. Acrobat 6 works to consolidate the individual subsets into a single subset. Acrobat 5 does not do this. Another solution is to refry the PDF [Hack #60] after assembly.

If you plan to edit PDF text at the source-code level using a text editor, avoid subsetting the PDF fonts. If you add text to the PDF that uses characters not present in the font subset, your text will not display.

Configure Distiller Font Subsetting

Distiller’s Fonts tab is the place to control the subsetting of embedded fonts. To prevent Type 1 fonts from subsetting, uncheck the “Subset embedded fonts” checkbox. All other fonts (e.g., TrueType) are always subset.

To the right of this checkbox you can put a threshold for deciding which fonts get subset. If your document uses 95% of the characters in a font and you don’t want that font subset, enter 94 into this field. Setting this to 100 means that every font will be subset.

Configure Ghostscript Font Subsetting

To prevent Type 1 font subsetting, set /SubsetFonts false in your joboptions file or add -dSubsetFonts= false to your command line. If you desire font subsetting, set these to true instead of false.

To change the threshold for deciding which fonts get subset, set /MaxSubsetPct 100 in your joboptions file or add -dMaxSubsetPct= 100 to your command line. Replace 100 with your desired setting.

Share a PDF Network Printer with Samba

Share a PDF printer with your entire network using Ghostscript, Samba, and Linux.

Ghostscript lets you freely print to PDF. However, maintaining Ghostscript on every client in your enterprise can be a nuisance. Consider installing it on a single Linux server instead. Then, use Samba to share it as a PDF printer to your entire network.

Before creating a PDF printer server, install a local PDF printer [Hack #39] to test Ghostscript and make sure it fits your requirements. Note that some Linux distributions provide GNU Ghostscript (Version 7) instead of the more recent AFPL Ghostscript (Version 8). Factor this into your testing. You will probably want to compile AFPL Ghostscript for your Linux server, later.

The Server

Every Linux distribution should have Samba and Ghostscript packages that you can install painlessly. Use them. Later, consider downloading and compiling the latest AFPL Ghostscript.

Samba is powerful, so its configuration requires some skill and patience. Consult man smb.conf and edit smb.conf to suit your network. Exercise your favorite Internet search engine, and drop by http://us3.samba.org/samba/docs/using_samba/toc.html. When things aren’t working, consult the log files (e.g., /var/log/samba). Don’t forget to restart the samba service (e.g., /etc/init.d/samba restart) after changing smb.conf.

Create the directory /home/pdf_printer/output, and chmod it to 777. This is where new PDFs will be delivered. Share this directory with your network by adding this section to smb.conf and restarting Samba:

[pdf_output]
comment = Shared PDF Printer Output
path = /home/pdf_printer/output
; this next line is necessary only when security = share
guest ok = yes
browseable = yes
writeable = yes

In Windows, this share should be visible from the Network Neighborhood or My Network Places, as shown in Figure 4-16. If not, try digging into Entire Network Microsoft Windows Network. Also try the Search for Computers or Find Computer features. Sometimes, new resources aren’t visible immediately. Sometimes, client configurations must be reviewed and changed, too.

A few ways to find shared network resources in Windows
Figure 4-16. A few ways to find shared network resources in Windows

Now, let’s add a PDF Printer to Samba. Once you get it working, adapt the settings to your requirements. Maybe these settings are all you will need.

Download samba-print-pdf from http://ranger.dnsalias.com/mandrake/samba/, copy it into your server’s /usr/local/bin directory, and chmod it to 755. Open this script in an editor to see what it does, and possibly change things, such as its Ghostscript OPTIONS.

Add the following section to smb.conf. It should work with Samba’s share security model (security = share) or user security model (security = user). The user security model requires that a user provide a name and password before accessing the printer.

[pdf_printer]
comment = Shared PDF Printer
path = /tmp
; this next line is necessary only when security = share
guest ok = yes
printable = yes
use client driver = yes
print command = /usr/local/bin/samba-print-pdf %s \
/home/pdf_printer/output //%L/pdf_output %m %I "%J" &
lpq command =
lprm command =

Restart Samba and then try accessing the file share pdf_output from a client machine. If that works, you are ready to install the client printer.

The Windows Client

Install the Virtual Printer Kit (VPK) [Hack #39] . Right-click our network printer, pdf_printer, under My Network Places in the File Explorer. Select Connect . . . , and click OK. The Add Printer Wizard will open and ask which printer driver to install. Click Have Disk, browse over to the VPK printer driver that suits your client platform, and click OK. Select the Virtual PostScript Printer driver and click OK. Your new PDF network printer will appear in the computer’s Printers folder. Print a test page to make sure it works properly.

Later, copy these Virtual PostScript Printer files to the pdf_output share so that you can access them easily across your network.

Print to Image and Other Rasterizing Options

Thumbnail the cover or rasterize the entire document.

You might sometimes need to convert PDF to other graphics formats. You can easily add a “Print to Image” printer by following [Hack #39] and changing a few ingredients. Alternatively, rasterize your PDF documents using Adobe Acrobat or Photoshop. Because Photoshop gives you the most power, you might prefer to “Print to PDF” and then open these pages in Photoshop.

Install a PNG (or JPEG or TIFF) Printer

The procedure for creating a bitmap (e.g., TIFF, JPEG, PNG) printer is the same as the procedure for creating the PDF printer in [Hack #39] . The configuration is just a little different. In this example, we’ll configure a PNG printer, but you just as easily can create a JPEG or TIFF printer. The DEVICE option determines what gets created. We discuss alternative devices a little later.

Follow the PDF Printer instructions, except:

  1. Name the new printer GS png16m Printer instead of GS Pdf Printer.

  2. Name the new Redirected Port RPTPNG16M: instead of RPTPDF:.

  3. When configuring this new Redirected Port, name the options file C:\gs\png16m_printer.cfg instead of C:\gs\pdf_printer.cfg.

  4. When configuring this new Redirected Port, name the log file C:\gs\png16m_printer.log instead of C:\gs\pdf_printer.log.

  5. Create the file png16m_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=png16m
    -r72
    -dTextAlphaBits=4
    -dGraphicsAlphaBits=4
    -dAlignToPixels=0

    Using this procedure, you can create one printer for each image file format you commonly use.

“Print to Image” devices and options

The documentation that comes with Ghostscript (C:\gs\gs8.14\doc\index.htm) explains the available output devices (Devices.htm) and general options (Use.htm) that you can use in the configuration file. Tables Table 4-8 and Table 4-9 provide a quick, abbreviated reference to give you a glimpse of what’s possible.

Table 4-8. Some Ghostscript bitmap devices

Ghostscript device

Description

pnggray

Grayscale PNG

png16

16-Color (4-bit) PNG

png256

256-Color (8-bit) PNG

png16m

16-Million Color (24-bit) PNG

jpeggray

Grayscale JPEG

jpeg

Color JPEG

tiff24nc

16-Million Color (24-bit) TIFF

faxg3

G3 Fax with EOLs

Table 4-9. Some Ghostscript bitmap options

Ghostscript option

Description

-r<dpi resolution>

Sets the resolution of the output file in dots per inch. Screen resolution is commonly 72 dpi. To create thumbnails, set this to a low value, such as 20 dpi.

-dTextAlphaBits=<1|2|4>

Sets the text antialiasing. 4 yields the greatest smoothing.

-dGraphicsAlphaBits=<1|2|4>

Sets the graphics antialiasing. 4 yields the greatest smoothing.

-dJPEGQ=<0-100>

Sets the JPEG quality. Lower values yield greater compression at the expense of image quality.

Image output filenames

When printing a multipage document to one of these bitmap printers, the output filename must include the %d page number variable so that each page gets a unique filename. To pad this variable with three leading zeros, use %03d. On the Windows command line, the % must be represented by %%. Here are some example filenames that you might enter into the Save As . . . dialog box:

report_page-%d.png

Yields: report_page-1.png, report_page-2.png, . . .

book_pg-%03.png

Yields: book_pg-001.png, book_pg-002.png, . . .

tome_p-%04.png

Yields: tome_p-0001.png, tome_p-0002.png, . . .

Acrobat: Save As Image

Beginning with Acrobat 5, you can open a PDF and then Save As . . . to JPEG, PNG, or TIFF image files. From the Save As . . . dialog, click the Settings . . . button to configure image options. You can set the image resolution, color space, and compression, among other things.

Photoshop: Open PDF

Photoshop is an ideal place to manipulate bitmaps, so it makes sense to open your PDF right in Photoshop. If your original document isn’t a PDF, print one using Acrobat Distiller or our GS Pdf Printer [Hack #39] . Open it in Photoshop, then Save As . . . to whatever format you want.

Mac OS X: Preview

As mentioned in [Hack #2] , the Preview application that comes with Mac OS X lets you open PDF files and save them in a variety of graphics formats.

Print to SVG

Create SVG as easily as PDF using pstoedit, and then embed it into your web page.

Scalable Vector Graphics ( SVG) is an emerging web standard for describing vector drawings with XML (http://www.w3.org/Graphics/SVG/). It behaves more like PostScript than PDF. In fact, you can transform PostScript into SVG using pstoedit’s SVG filter. Close the loop by wiring these tools into one of our virtual printers and you’ll have “Print to SVG”!

Tip

You can also create SVG using vector-editing programs such as Adobe Illustrator, Corel Draw, or Karbon.

Tool Up

SVG viewers are freely available. Visit http://www.adobe.com/svg/ or http://www.corel.com/svgviewer/ to download an SVG plug-in for your web browser. Visit http://xml.apache.org/batik/svgviewer.html to learn about Squiggle, the SVG browser.

Follow [Hack #39] to install Ghostscript and our other virtual printer components. Pstoedit requires Ghostscript.

Download the pstoedit installer from http://www.pstoedit.net/pstoedit/. This installer includes the shareware SVG filter. During installation, make sure to select this optional component. pstoedit is free software, but this SVG filter is not. The filter distorts its output by altering colors and scrambling text until you purchase and install a registration key. The pstoedit web site has a link to where you can purchase this key.

Tip

pstoedit also includes an alternative, free SVG filter. To use this free filter, replace -f svg with -f plot-svg in the configurations, discussed shortly.

Using pstoedit

Test your installation by running pstoedit from the command line:

pstoedit -f svg c:\gs\gs8.14\examples\tiger.eps c:\tiger.svg

Open tiger.svg in your viewer and you should find this classic character snarling at you. Without its registration key, the SVG filter will deliberately upset tiger’s colors, so she might appear blue instead of orange. Try using the plot-svg filter instead to see her true colors:

pstoedit -f plot-svg c:\gs\gs8.14\examples\tiger.eps c:\tiger.svg

After using this command, I edited the SVG file. I changed the g tag’s transform attribute to get all of the tiger back into view for the screenshot in Figure 4-17.

Tiger in SVG
Figure 4-17. Tiger in SVG

Create an SVG Printer

The procedure for creating an SVG printer is the same as the procedure for creating the PDF printer in [Hack #39] . The configuration is just a little different.

Follow the PDF Printer instructions, except:

  1. Name the new printer SVG Printer instead of GS Pdf Printer.

  2. Name the new Redirected Port RPTSVG: instead of RPTPDF:.

  3. When configuring this new Redirected Port, name the log file C:\gs\svg_printer.log and configure the port with the settings shown in Table 4-10.

Table 4-10. RedMon port properties

Field

Value

Redirect this port to the program:

                              
                                 C:\pstoedit\
                              
                              pstoedit.exe

Arguments for this program are:

-f svg - "%1"

Output:

Prompt for Filename

Run:

Minimized

Print a test page to see how it works. If the page isn’t created, review the log file and double-check your settings. When you look at the SVG test page you will find that TrueType text has lost its encoding and doesn’t display properly. This is an unfortunate limitation in the pstoedit SVG filter.

SVG on the Web

Use a belt-and-suspenders approach to adding SVG to your web pages. If the client ignores the OBJECT tag, it can fall back to the enclosed EMBED tag. For example:

<object type="image/svg+xml" data="tiger.svg" 
title="Roar!" width="400" height="400">
  <embed type="image/svg+xml" src="tiger.svg"
  width="400" height="400"
  pluginspage="http://www.adobe.com/svg/viewer/install/">
</object>

Adobe specifically recommends against using the OBJECT tag when embedding SVG in an HTML page. For details, visit http://www.adobe.com/svg/viewer/install/.

Print Over the Internet

Print via HTTP by submitting your print streams as HTML form data.

Printing over the Internet brings the way people like to read and write to the way we plumb information in the 21st century. The idea is to enable authors to create documents using their favorite editor and then print it to a web site. Once on the web server, the PostScript print stream can be converted to PDF and posted online for reading or downloading. In this scenario, the author controls the source document and is responsible for maintenance.

Tip

This hack uses HTTP file submission to transfer PostScript to a web server. A more formal solution would use CUPS (http://www.cups.org). For a CUPS-based PDF creation server, try Alambic (http://alambic.iroise.net). Alambic supports HTTP and SMTP interfaces.

This hack demonstrates how to "print” a PostScript print stream to a web server. In our examples, we won’t be printing to an elaborate document hosting service. Instead, we will print to the simple http://www.ps2pdf.com web site.

Warning

Currently, http://www.ps2pdf.com uses an old version of Ghostscript, so printing to your own, local version of Ghostscript will yield a better PDF.

Download and Install

Visit http://www.pdfhacks.com/submit_file/ and download submit_file-1.0.zip. Unzip this archive, and then copy SubmitFile.exe to a convenient location. This is a simple program that uses the Windows WinInet API to submit a local file to a web server. It then opens the default web browser to view the server’s response. The source code is available and you should consult it for HTTP submission details.

Install a ps2pdf.com Printer

The procedure for creating an Internet printer is the same as the procedure for creating the PDF printer in [Hack #39] , except you don’t need to install Ghostscript. The configuration is also a little different.

Follow the Print to PDF instructions, except:

  1. You don’t need to install Ghostscript.

  2. Name the new printer ps2pdf.com Printer instead of GS Pdf Printer.

  3. Name the new Redirected Port RPTWEB: instead of RPTPDF:.

  4. When configuring this new Redirected Port, use the settings in Table 4-11.

    Table 4-11. RedMon port properties

    Field

    Value

    Redirect this port to the program:

                                        
                                           C:\redmon17\
                                        
                                        RedRun.exe

    Arguments for this program are:

                                        
                                           C:\pdfhacks\
                                        
                                        SubmitFile.exe/convert/convert.cgiwww.ps2pdf.cominputfile%1

    Output:

    Program Handles Output

    Run:

    Minimized

  5. Name the Redirected Port log file C:\pdfhacks\web_printer.log instead of C:\gs\pdf_printer.log.

  6. Click OK to accept the new port settings.

  7. Click OK to accept the new printer settings and close the dialog.

The RedRun program takes the PostScript print stream and creates a temp file for it. RedRun then runs the program SubmitFile, replacing the %1 with the temp filename. Note that you should not put quotes around this %1, because RedRun seems to pad the temp filename with whitespace that disrupts the SubmitFile arguments.

You can run SubmitFile from the command line, which is useful for debugging. It takes arguments in order:

SubmitFile <cgi path> <cgi server name> \
<html form field name> <local filename of upload>

Test Your ps2pdf.com Printer

Open the ps2pdf.com Printer properties dialog, click the General tab, and click Print Test Page. When your PDF is ready for download from http://www.ps2pdf.com, a browser will open with a hyperlink to follow.

If an error occurs, check the log file for feedback from RedRun or SubmitFile.

Note that the previous configuration is tailored to the current state of http://www.ps2pdf.com. The site administrators might choose to alter it at any time, requiring you to change this printer’s configuration.

Create a PDF Album of Your Digital Pictures

Quickly prepare your photos to share with family and friends.

With a digital camera you can easily create hundreds of photographic images. Preparing these pictures to share with your family and friends is a more difficult task. Consider creating a photo album with PDF. It makes a clean package that you can easily distribute, and its thumbnails feature is ideal for rapid navigation.

Most importantly, you can quickly and easily create one, shown in Figure 4-18, with free software. ImageMagick can create a single PDF from a folder of photographs in a snap. Create a lightweight edition suitable for email by simply adding downsample and compression settings.

Collecting photos into a distributable package that is easy to navigate
Figure 4-18. Collecting photos into a distributable package that is easy to navigate

Install ImageMagick

Visit http://www.imagemagick.org to learn about this powerful toolset and to download a Windows installer. The installer also unpacks documentation. We will use the convert tool, which is described in convert.html.

Convert Images to PDF

These examples use JPEG input images, but you can adapt them for use with other image types. Find a folder of images, open a command prompt [Hack #79] in this folder, and whisper this cantrip:

convert -density 100 -quality 85 \
-page "800x800>" -resize "800x800>" *.jpg album.pdf

When it is done, open album.pdf in Acrobat/Reader. Each image gets one PDF page, and they are ordered alphabetically by filename. To view all images with a uniform zoom, select View Actual Size. View the thumbnails by selecting View Navigation Tabs Pages (Acrobat 6) or Window Thumbnails (Acrobat 5). Select any image and copy it to the clipboard for use elsewhere; this works in Reader as well as Acrobat.

Let’s take a look at our command parameters:

density

This is the resolution of output images measured in dots per inch (dpi). The default is 72 dpi. Changing it doesn’t affect the resulting image quality. Rather, it affects the logical, outer dimensions of the image. For example, a 1600 1200-pixel image at 200 dpi is 8 6 inches. At 100 dpi it is 16 12 inches. I chose 100 dpi because it strikes a good balance between on-screen, Actual Size viewing and paper printing (150 dpi is good for printing photos on most 600 dpi printers).

quality

This is the JPEG compression applied to the images as they are packed into the PDF. 0 yields the poorest image quality but the greatest compression. 100 yields the greatest image quality but the poorest compression. The default is 75.

page

This describes the outer dimensions of the PDF page, in pixels. If an image is smaller than these dimensions, the page is reduced to fit the image. Omitting this option causes large images to be constrained by (and squeezed into) the default, letter-page size. Set it to match the resize option.

resize

This describes the maximum dimensions (in pixels) for all output images. The > symbol means that images smaller than this are not changed, and images larger than this are downsampled to fit. Decrease these dimensions to yield a smaller PDF file size. Increase these dimensions to improve image fidelity. Set page to match.

To demonstrate how these work together, here is another example. If your camera creates images at 1600 1200 pixels and you want to create a high-quality archive of these images, consider using:

convert -density 200 -quality 95 \
-page "1600x1600>" -resize "1600x1600>" *.jpg archive.pdf

Finishing Touches

In Acrobat you can correct image rotation, reorder images, and add bookmarks. I like to configure the PDF to open thumbnails automatically. See [Hack #62] for more information.

Tip

You can create similar PDF albums with Adobe Photoshop Album as well, though it costs around $50.

Print to Fax on Windows

Treat fax machines like remote printers instead of remote copiers.

Faxing a document traditionally involves two fax machines: one that scans your document and one that prints your document. If the document in question is already stored on a computer, it makes more sense to print the document from the computer to the target fax machine. This yields a much higher-quality fax, and it is much more convenient. On a Windows machine with a fax modem, you can install a Fax printer that behaves like any other system printer.

Tip

Faxes tend to look bad because the process of scanning a document adds noise, skews text, and generally degrades the appearance. Artwork and photographs suffer the most corruption. Printing a document to the target fax machine, on the other hand, dispenses with scanning. Text looks sharp, and images are preserved with dithering.

Windows XP and Windows 2000 will create a Fax printer when you install a fax-capable modem (Start Setting Control Panel Phone and Modem Options Modems Add . . . ). Using Acrobat or your authoring program, print your document to this Fax printer and a wizard will open. This fax wizard asks for the recipient’s phone number and enables you to fill in a cover page. Upon completion, your modem will dial out to the destination fax machine and send your document.

Tip

A useful series of Windows fax articles is available from http://labmice.techtarget.com/windows2000/printing/fax.htm.

If you fax PDFs frequently, consider adding a Print to Fax item to the PDF right-click context menu.

Windows XP and 2000:

  1. In the Windows File Explorer menu, select Tools Folder Options . . . and click the File Types tab. Select the PDF file type and click the Advanced button.

  2. Click the New . . . button and a New Action dialog appears. Give the new action the name Print to Fax.

  3. Give the action an application to open by clicking the Browse . . . button and selecting Acrobat.exe, which lives somewhere such as C:\Program Files\Adobe\Acrobat 6.0\Acrobat\. Or, use Reader (AcroRd32.exe) instead of Acrobat.

  4. Add arguments after Acrobat.exe or AcroRd32.exe like so:

    "C:\Program Files\Adobe\Acrobat 6.0\Acrobat\Acrobat.exe" /t "%1" Fax
  5. Click OK, OK, OK and you should be done with the configuration.

To integrate fax features into your network, use HylaFAX. Visit http://www.hylafax.org and http://www.ifax.com, and consult the fa.hylafax newsgroup.

Convert Incoming Faxes to PDF on Linux

Wrap an incoming fax in PDF and deliver it by email.

Before PDF and before email, we had fax. Today, we still have fax. Integrate fax with your 21st-century lifestyle using HylaFAX. HylaFAX turns your Linux box into a fax server. For details, visit http://www.hylafax.org and http://www.ifax.com. Here, we discuss configuring HylaFAX so that it will deliver incoming faxes to a given email address as a PDF attachment.

Install the HylaFAX server package from your favorite Linux distribution. During installation, a FaxMaster email alias should be created that points to the user responsible for maintaining the server. In this hack, all incoming faxes will be emailed to the FaxMaster as PDF. After installation, run faxsetup -server.

After a fax is received, HylaFAX’s faxgetty invokes the faxrcvd script, which in turn executes FaxDispatch (typically located in /var/spool/hylafax/etc) to set configuration parameters. FaxDispatch is where you can control how incoming faxes are routed. Your installation might include a sample FaxDispatch file, or you might need to create one. Read man faxrcvd for details about FaxDispatch.

This sample FaxDispatch file configures HylaFAX to email all incoming faxes to the FaxMaster as PDF attachments. Additional, commented-out lines give an idea of what else is possible:

## Default FaxDispatch file - routes all inbound faxes to FaxMaster as PDF
## Consult the faxrcvd(8C) man page for more information
##

SENDTO=FaxMaster;             # by default email to FaxMaster
FILETYPE=pdf;                 # in PDF format

## This excerpt from the man page gives you an idea of what's possible here
##
## You can route by sender's TSI
#case "$SENDER" in
# *1*510*526*1212*) SENDTO=sam;;      # Sam's test rig in Berkeley
# *1*415*390*1212*) SENDTO=raster@asd;; # 7L Xerox room, used for scanning
# *5107811212)     SENDTO=peebles@mti;;  # stuff from home
#esac

## and/or by device
#case "$DEVICE" in
#  ttyS1)            SENDTO=john;;      # all faxes received on ttyS1
#  ttyLT0)           SENDTO=mary@home;; # all faxes received on ttyLT0
#esac

## and/or by caller id
#case "$CIDNUMBER" in
# 435*)       SENDTO=lee; FILETYPE=pdf;; # all faxes from area code 435
# 5059627777) SENDTO=amy; FILETYPE=tif;; # Amy wants faxes in TIFF
#esac

Darren Nickerson

Get PDF Hacks now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.