Tech Notes

Tech Note #20130006

When Apple handed over support for the CUPS image printing filters to The Linux Foundation OpenPrinting Project, they made it necessary for one to take a number of extra steps, after CUPS itself is installed, to enable direct printing of image files on a CUPS server. In addition, the method used by the OpenPrinting Project filters to filter images is much less than optimum, which can yield extremely large print files that are slow or impossible to print, especially on older postscript printers.

Problem Description:

With the advent of the new PDF workflow model employed by later versions of CUPS, all image files that are to be printed on a CUPS printer should be converted to PDF, since PDFs are the new coin of the realm or, if you prefer, lingua franca of modern CUPS-based printing.

Herewith is the rational for this state of affairs: One of the decisions which was made at the OSDL Printing Summit in Atlanta, in 2006, and widely accepted by all participants was to switch the standard print job transfer format from PostScript to PDF. This format has many important advantages, especially: PDF is the common platform-independent Web format for printable documents, hence it is portable; easy post-processing (N-up, booklets, scaling, ...); easy color management support; easy high color depth support (> 8bits/channel); easy transparency support; smaller files.

As of CUPS 1.6, the imagetopdf filter has been unbundled and handed off to The Linux Foundation OpenPrinting Project. Here is the relevant note from the CUPS 1.6 release notes: The parallel and serial backends, php_cups scripting module, and bannertops, commandtoescpx, commandtopclx, imagetops, imagetoraster, pdftops, rastertoescpx, rastertopclx, and texttops filters are now provided as part of a separate cups-filters project hosted by The Linux Foundation.. Although imagetopdf is not specifically mentioned, it is the successor to imagetops, which is mentioned, and, follwoing this relationship to its logical conclusion, the OpenPrinting Project is indeed where you'll find imagetopdf.

Why Use sam2p:

OK, so if imagetopdf can be found among the OpenPrinting Project filters (which you may have already downloaded and installed), why not use it and get on with our lives?

There is actually a very good reason. The OpenPrinting Project image filter employs direct conversion of images to ASCII-encoded binary, which is well-known for producing huge PDF files. If you are going to be sending such files to a postscript printer, transmission time may contribute to a significant portion of your print job's time. Who needs to be sending huge files to a printer for a couple of minutes, only to have it render a single page?

On top of that, when you consider the prerequisites of sam2p vs. those of the OpenPrinting Project filters, you may find sam2p much simpler to install (we did).

Here's a list of the relevant reasons why the author of sam2p recommends his program over other image converters:

Problem Resolution:

Since a texttops filter is included in the list of filters provided by The OpenPrinting Project, one might infer that, in order to print text files, one can simply go back to one's local.convs file, replace all instances of "texttopdf" with "texttops", and then change the instances of "application/pdf" on each texttops line to "application/postscript".

Too bad this won't fly. The included texttops filter is actually just a shell script which invokes texttopdf and then pipes the output through pdftops. Thus, if texttopdf doesn't work, texttops won't work either.

We have described elsewhere, in Tech_20130003, how to obtain and build the filters source from The OpenPrinting Project. We'll assume that you've followed those instructions and are now ready to build the texttopdf filter. Build it like this:

cd cups-filters-1.0.34
make texttopdf

Now that we've built the texttopdf filter (we're assuming that the pdftops filter has already been built and installed), we need to install it, along with the character sets that it uses. While we're at it, we'll install the texttops filter, just in case any older PPDs mention it:

su
cp texttopdf /usr/lib/cups/filter
cp filter/texttops /usr/lib/cups/filter
chmod u=rwx,go=rx /usr/lib/cups/filter/*
mkdir /usr/share/cups/charsets
cp --preserve charset/* /usr/share/cups/charsets
cd /usr/share/cups/charsets
chown root:root *
chmod ug-w *
ln -s pdf.utf-8.simple pdf.utf-8

Now, we must check the /etc/cups/local.convs file (or whatever other name you've used) to make sure that text files will get converted using the proper filters. This file should look something like:


#
#   Local MIME conversions file for CUPS Filters.
#
#   This file describes how to convert files of one MIME type to files
#   of another.
#

########################################################################
#
# Text filters...
#

application/x-cshell    application/pdf              0    texttopdf
application/x-csource   application/pdf              0    texttopdf
application/x-perl      application/pdf              0    texttopdf
application/x-shell     application/pdf              0    texttopdf
text/plain              application/pdf              0    texttopdf
text/html               application/pdf              0    texttopdf

########################################################################
#
# PDF filters
#

application/pdf   application/postscript             66   pdftops

########################################################################
#
# Banner types...
#

application/vnd.cups-pdf-banner   application/pdf    33   bannertopdf

The character set mentioned in /usr/share/cups/charset/pdf.utf-8.simple, which was one of the files that we installed, is FreeMono, supposedly a replacement for Courier. This font is necessary to convert text files to PDF files, the first step in printing a text file. Therefore, for text printing to work this font must be downloaded from the GNU FreeFont site, http://ftp.gnu.org/gnu/freefont/.

Download the latest ttf, tar file and then extract it:

tar -xvzf freefont-ttf-20100919.tar.gz

The font files are copied to the system fonts directory:

su
mkdir /usr/share/fonts/FreeFont
cp freefont-20100919/*.ttf /usr/share/fonts/FreeFont

You should now be able to convert a text file to a PDF by running the texttops filter using the cupsfilter test program like this:

cupsfilter -m application/pdf -p /etc/cups/ppd/MyLaser.ppd \
  /etc/cups/local.convs >/home/joeblow/testprint-pdf.prt

Inspect the debugging output from cupsfilter and check to make sure that texttopdf didn't windge or give up. If it worked OK, you should be in good shape for printing text files.

As a final note, you may wish to avoid obtaining yet another font and use the original Courier and Symbol fonts in the UTF-8 character set. If you do this, you won't have to install the FreeFont fonts as described above. You will need to break the pdf.utf-8 symlink in /usr/share/cups/charsets and create a replacement pdf.utf-8 that looks like this:


charset utf8

#
# This file defines the font mappings used for Unicode/UTF-8 text printing
# through PDF.
#
# Each line consists of:
#
#   first last direction width normal bold italic bold-italic
#
# First and last are the first and last glyphs in the font mapping
# that correspond to that font; contrary to PostScript printing
# they only select the font. To find the glyph the complete unicode
# character will be looked up in the (3,1) resp. (3,0) cmap of the
# TrueType font. The glyph values are hexadecimal.
#
# Direction is the string "ltor" or "rtol", indicating left-to-right or
# right-to-left text.
#
# Width is the string "single" or "double"; double means that the glyphs
# are twice as wide as ASCII characters in the Courier typeface.
#
# "Normal", "bold", "italic", and "bold-italic" are the typefaces to use
# for each presentation.  If characters are only available in a single
# style then only one typeface should be listed (e.g. "Symbol")
#
# Each font that is listed will be used (and downloaded if needed) when
# printing.
#

0000 00FF ltor single Courier Courier-Bold Courier-Italic Courier-Bold-Italic
0100 01FF ltor single Courier Courier-Bold Courier-Italic Courier-Bold-Italic
0200 02FF ltor single Courier Courier-Bold Courier-Italic Courier-Bold-Italic
0300 03FF ltor single Symbol
0400 04FF ltor single Courier Courier-Bold Courier-Italic Courier-Bold-Italic
0500 05FF rtol single Courier
1E00 1EFF ltor single Courier Courier-Bold Courier-Italic Courier-Bold-Italic
2000 20FF ltor single Courier Courier-Bold Courier-Italic Courier-Bold-Italic
2100 21FF ltor single Courier Courier-Bold Courier-Italic Courier-Bold-Italic
2200 22FF ltor single Symbol
2300 23FF ltor single Symbol