Power Printing With MagicFilter
Printing with Linux can be a daunting experience—it needn't be. If you really want to become a printing expert, check out the Linux Printing HOWTO, the Linux Printing Usage HOWTO and the lp family of man pages. However, if you just want your Linux box to print text, PostScript, graphics and other formats you throw at it today, read on.
When something sounds too good to be true, it usually is. The one exception to that rule is MagicFilter-1.2, by H. Peter Anvin. It's an extensible, customizable print filter that enables just about any kind of printer to print just about any kind of file automatically.
MagicFilter has two jobs. First, it detects the type of file being printed. It does this by searching for key strings at specific offsets in the file. It does not rely on file names or extensions as indicators of file type. For instance, if the file's first two characters are %!, it's processed as a PostScript file. Other file types, such as gifs, bmps, etc., are detected by similar rules. MagicFilter's second job is to call an appropriate conversion utility to print the file on your specific printer. If you happen to try to print something unprintable, like a binary file, the job is aborted, and you'll be advised (via e-mail) that your file couldn't be printed.
The obvious benefit is that with MagicFilter installed, you can enter the command:
lpr first.txt second.ps third.gif fourth.jpeg\ README.gz
at the prompt, and all five files will spool up and print in fine style. Another perhaps greater benefit is that most packages for Linux come preconfigured with lp or lpr as the default printer. With MagicFilter installed, all of your favorite programs like Pine, Netscape, Applixware, etc. should print fine right out of the box. I'll go into more detail on printing with applications later.
Before you can build MagicFilter, you're going to need some supporting packages. At a minimum, you need the gcc compiler. MagicFilter's Makefile is generated by a script called configure, that scans the directories in your path and caches the locations of any conversion utilities that it finds. If configure doesn't find some of the utilities, MagicFilter will build anyway, but without the ability to print some file types. Table 1 shows the support packages needed for varying levels of file printing ability.
The staircase effect mentioned in Table 1 occurs when a printer omits the carriage return from end-of-line sequences. If you want to see the staircase effect in action, send a short text file directly to your printer device by running this example (substituting your lp device name):
cp /etc/group /dev/lp1
Decide what level of robustness you need in MagicFilter, install those supporting packages, then build magicfilter. I have listed some sources for these packages at the end of this article.
All right, let's assume you have all your support packages identified and installed somewhere in your path. You've obtained the file magicfilter-1.2.tar.gz and as root, moved it to a suitable location. (I always use /usr/local.) Unpack the file with this command:
tar -xzf magicfilter-1.2.tar.gz
This command unpacks MagicFilter into the newly-created directory /usr/local/magicfilter-1.2. Change directory to magicfilter-1.2, and run the configure script. Note the output displayed on your screen; you will probably see a few packages that configure didn't find. Peter Anvin assures me that if you have all the packages shown in Table 1 installed and in your path, you will build a fully-functional magicfilter program. Some of the packages searched for have been replaced (in functionality, at least) by newer ones in the support packages. Anyway, now run make; next, run make<\!s>install. Afterwards, the directory /usr/local/magicfilter-1.2/filters will contain about 40 scripts for just about any printer you are likely to encounter. The actual magicfilter binary may be in /usr/local/bin. What you do at this point is copy or move the script(s) for your printer(s) to /usr/local/bin. For example, if you have a Canon BJ-200ex printer, your script is bj200-filter. Some printers may not have a script per se, but there should be a script that works for almost any printer.
Optionally, you can run make<\!s>install_filters, and all the scripts will be copied to /usr/local/bin. It's worth noting at this point that /usr/local/bin (or wherever you've installed MagicFilter) does not need to be in your path. When we reference these files next, we will use absolute path names.
Since I'm writing about Linux, which uses the BSD printing system, I will only address the Linux-specific installation in the /etc/printcap file. Be advised that not all flavors of Unix implement this printing system. Edit the /etc/printcap file and weave in a call to your printer's script as an input filter. Here is an example for a system with two printers, a HP LaserJet 4 and a HP DeskJet 550C on /dev/lp1 and /dev/lp2, respectively:
pencil|lp|PostScript|ljet4|HP LaserJet 4:\ :lp=/dev/lp1:sd=/var/spool/lpd/pencil:sh:mx#0:\ :if=/usr/local/bin/ljet4-filter: crayon|dj550c|color|HP DeskJet 550C:\ :lp=/dev/lp2:sd=/var/spool/lpd/crayon:sh:mx#0:\ :if=/usr/local/bin/dj550c-filter:
The syntax for the /etc/printcap file is a subject in itself. See the Linux Printing-HOWTO a complete description. Peter points out, “Note the alias `lp' for the default (text) printer, and `PostScript' for the preferred PostScript printer.”
Next, kill and restart your lpd (print demon). Mine killed okay, but it wouldn't restart properly; so, I rebooted. Following the reboot, lpd was indeed running again.
|Bitcoin on Amazon! Sort of...||Sep 28, 2016|
|Free Today: September Issue of Linux Journal (Retail value: $5.99)||Sep 27, 2016|
|nginx||Sep 27, 2016|
|Epiq Solutions' Sidekiq M.2||Sep 26, 2016|
|Nativ Disc||Sep 23, 2016|
|Android Browser Security--What You Haven't Been Told||Sep 22, 2016|
- Free Today: September Issue of Linux Journal (Retail value: $5.99)
- Bitcoin on Amazon! Sort of...
- Android Browser Security--What You Haven't Been Told
- Epiq Solutions' Sidekiq M.2
- Nativ Disc
- The Many Paths to a Solution
- Identity: Our Last Stand
- Readers' Choice Awards 2013
- Tech Tip: Really Simple HTTP Server with Python
Pick up any e-commerce web or mobile app today, and you’ll be holding a mashup of interconnected applications and services from a variety of different providers. For instance, when you connect to Amazon’s e-commerce app, cookies, tags and pixels that are monitored by solutions like Exact Target, BazaarVoice, Bing, Shopzilla, Liveramp and Google Tag Manager track every action you take. You’re presented with special offers and coupons based on your viewing and buying patterns. If you find something you want for your birthday, a third party manages your wish list, which you can share through multiple social- media outlets or email to a friend. When you select something to buy, you find yourself presented with similar items as kind suggestions. And when you finally check out, you’re offered the ability to pay with promo codes, gifts cards, PayPal or a variety of credit cards.Get the Guide