Hack 45 Print to Image and Other Rasterizing Options

figs/expert.gif figs/hack45.gif

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.

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

4.15.1.1 "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.


4.15.1.2 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, . . .

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

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

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