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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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:

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

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.

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.

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

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.

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.

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?

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

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.

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.

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.

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

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

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.

You already installed Ghostscript, RedMon, and our Virtual Printer Kit, right? All that remains is to install and configure your PDF 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.

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.

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.

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.

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.

With each new version of Acrobat, Adobe introduces an updated version of the PDF specification. They go together, as shown in Table 4-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.

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.

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 .

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

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.

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.

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.

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.

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.

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.

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.

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.

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

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.

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.

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.

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.

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.

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:

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

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.

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.

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