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)

Advertisements

5 thoughts on “Printing to a PDF file using CUPS

  1. Awesome guys, I have been looking for this information all around, there are no online information or any website or articles written about this information. I got an email about this from my friend, it was very important for me. The information you people have given here is really very helpful and will absolutely help in resolving my problem. This has been one of the finest articles about this. I really appreciate your work. Hope you people here keep writing good stuff like this!

  2. hi!,I love your writing so so much! proportion we be in contact extra approximately your article on AOL? I need a specialist on this house to resolve my problem. May be that’s you! Having a look forward to peer you.

  3. I have a question.
    I have lpr (cups) set up to print to a virtual PDF printer. This is Red Hat Linux that I’m on. It uses the cupsd-pdf.conf file. My question is, Why do I get a much larger file than the plain text file that I am trying to print. For instance, if I print a 362,554 byte report to the PDF printer, I get a 24,515,539 byte file. This is ridiculous. I understand that PDF files will be larger, but this is 67 times larger. Is there anything I can tweak in the configuration file?

    Doug

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s