Tech Notes

Tech Note #20130004

When Apple handed over support for the CUPS text 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 text files on a CUPS server.

Problem Description:

Text files that are to be printed on a CUPS printer must be converted to postscript, since postscript is the coin of the realm or, if you prefer, lingua franca of CUPS-based printing. In earlier versions of CUPS, text files were converted to postscript via a filter named texttops, which was included in the CUPS build.

As of CUPS 1.6, the texttops 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..

Sadly, this note is somewhat disingenuous. With the new PDF workflow scheme implemented by Canonical under the scope of The OpenPrinting Project, texttops is actually replaced by texttopdf which must then be followed by pdftops.

For texttopdf to work, one or more character sets must be installed and then, one or more fonts that are referenced in the character sets may need to be installed.

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