Printing to a PDF file using CUPS

Although nearly every GNOME or KDE application has native support for printing to PDF files, there are still applications out there which do not support this feature. One example are Windows applications ran under WINE.

Although WINE-emulated Windows applications use the CUPS printing system, they are unable to print directly to a PDF file, like GNOME, KDE or Mac OS X applications do. Fortunately, there exists CUPS-PDF, an open source project which implements a virtual PDF printer. WINE-emulated Windows applications can print to the CUPS-PDF virtual printer which will magically create a PDF file from any print job sent to it and place it under directory /var/spool/cups-pdf/$USER.

CUPS-PDF works by installing a CUPS printer, named Cups-PDF, supported by the custom cups-pdf backend which takes a PostScript input file and writes out a PDF output file using GhostScript’s pdfwriter driver.

I have been experiencing problems when converting PostScript print jobs to PDF documents. Fedora Core 5 uses ESP GhostScript 8.15 by default and it seems to have problems with embedded images. Although the PDF document seems to get written successfully, trying to open it up using Adobe’s Acrobat Reader throws a “Drawing error” message and an blank page. Using AFPL GhostScript 8.53 instead seems to fix the problem and it’s currently working pretty very well for me.

I have created two custom RPM packages for Fedora Core 5:

  • cups-pdf-gs-8.53-1.src.rpm

    This RPM package wraps AFPL GhostScript 8.53, relocated under /usr/lib/cups-pdf-gs-8.53, along with Type1 and PFM fonts taken out from the GhostScript and urw-fonts packages.

    The AFPL GhostScript’s gs processor is able to transform a PostScript document with images embedded into a PDF file which Adobe Acrobat Reader is able to display and print.

  • cups-pdf-2.1.0-1.src.rpm

    This RPM package is based upon the original but includes a few tweaks:

    1. A tweaked color PostScript PPD file.

      I had to adjust the *ImageableArea directives (which control margins) since the original values caused undesired clipping and wrapping in the generated PDF documents.

      The tweaked PPD file also changes the default paper layout from Letter to A4, since the latter is what most people use here in Europe.

    2. A tweaked cups-pdf.conf file.

      The original CUPS-PDF configuration file, cups-pdf.conf, uses /usr/bin/gs to convert from PostScript to PDF. I had to adjust the path to the GhostScript interpreter (GhostScript directive) in order to point to one packaged inside the AFPL GhostScript 8.53 RPM packaged, which lies at /usr/lib/cups-pdf-gs-8.53/bin/gs

One last thing: the %postinstall script of cups-pdf-2.1.0-1.src.rpm invokes /usr/sbin/lpadmin -p Cups-PDF -v cups-pdf:/ -m PostscriptColor.ppd -E to set the virtual PDF printer up. However, I have noted that lpadmin installs the PostscriptColor.ppd file, but changes the paper defaults from A4 to Letter.

UPDATE:

As of ghostscript-8.15.1-8 (ESP GhostScript 8.15 r128), the problem with the pdfwriter seems to have been fixed: Fix pdfwrite (bug #187834)