Friday, March 12, 2010

Other: Faxing in the Geekiest Way Possible

I don't own a fax machine. I almost never need one. However, today I need to fax some forms to my future (crossing fingers) employer. Yes, I could go down to the local copy shop and pay an absurd amount, but I'm cheap. However, I having successfully faxed stuff in the past using FreeBSD, but it's so rarely done that I have to mess around each time to remember how to do it. I'm writing this post as much for my benefit as anyone else's.
Background:
  • I have an old computer which I used to dual-boot with FreeBSD (which has the 6-year-old FreeBSD 5.2.1 installed but isn't worth upgrading), but is now my lame Windows XP box for stuff that won't run on FreeBSD. (I still cannot for the life of me get Flash to work on FreeBSD since I upgraded to 8.0, for instance.)
  • I also have a desktop, now running FreeBSD 8.0, which I use for Real Stuff, like email and playing Puzzle Pirates (cough).
  • The old computer has a PCI hardware modem card, which I had to purchase when I bought it as (a) I was still dialing up, and (b) FreeBSD (and Linux) has a very hard time dealing with the winmodem (aka software modem, aka losemodem) that has been standard for years. (If you're really interested, you can read about the difference here.) The newer desktop has a built-in losemodem. (I could move the hardware modem card from the old computer to the new one, but I'm too lazy to open up both computers.)
  • I first figured out how to do this because I wanted to get tickets for Rachael Yamagata at the Troubadour last year. TicketBastard wanted to charge me almost as much in fees for 4 tickets as the tickets would cost themselves! Screw that. The only other ways to get tickets were to try to get some at the box office the night of the show (and it ended up being sold out) or to fax an order to the venue directly. I felt extremely smug when I got my ticket confirmation!

There's a lovely open-source package around for Unix-like operating systems called efax, which handles the whole faxing thing from the command-line. (I'm old-school and generally avoid GUIs when possible because they confuse me. Seriously.) efax, however, needs a very specific TIFF file format. Here are the FreeBSD ports you will need to have installed:

  • efax
  • tiff
  • netpbm
  • ghfaxviewer (optional)

Anyway, without further ado, here's how I got my paper forms faxed to where they needed to go. I assume this process would also work on Linux. (For brevity and to save myself embarrassment, I've left out all the dead-ends.)

  1. Scan in the files if they're hard copies. I have a crappy scanner which is easier to use under Windows. I saved the file in the tiff format, unable to remember if efax would like it. (efax did not.)
  2. Copied those files over to my FreeBSD-8.0 machine, which I was going to use for the re-formatting.
  3. My scanner software wrote the files with 8 bits/sample, but efax (and its formatting program efix) can only deal with 1 bit/sample. I couldn't find a program, either command-line or the GIMP, which would let me change that.
  4. Converted the tiff files to PBMs (ASCII format, not Raw) using GIMP. I might have been able to do it with a combination of tiffbw (to make a grey-scale file as efax doesn't like color PNM files, only b&w PBMs) and tifftopnm (which only makes b&w PBM files if the input file is B&W) programs, but I already had GIMP open.
  5. I needed to fax two pages. It would probably have been easier to send them one at a time, as I had done in the past, but this time I wanted to figure out how to send them both at the same time. The TIFF format can, fortunately, handle multi-page files.
  6. Converted the PBM files back to tiff, in the Group 3 (fax) compression format, using the following command:
    pnmtotiff -g3 -rowsperstrip 2500 file1.pbm > file1.g3
    pnmtotiff -g3 -rowsperstrip 2500 file2.pbm > file2.g3
    I used a big value for rowsperstrip because efax can't handle multi-strip TIFF files, so you want to make sure pnmtotiff can fit everything in one strip. Anything over 2500 should be enough; pnmtotiff will just write as many rows under the number as it needs to.
  7. (Skip this step if you only have one page to fax.) Ran the following to concatenate the files into a multi-page TIFF file:
    tiffcp -c g3 file1.g3 file2.g3 fax.g3
    You can add as many input files to the command line as you want; the last file is the output file.
  8. You can preview the file using a package like ghfaxviewer, which was the only FreeBSD port I could find which handled multi-page G3 tiff files.
  9. Here I copied the final file over to my old FreeBSD box with the hardware modem.
  10. If you need to figure out the device file for the modem, FreeBSD seems to name it /dev/ttyd#. I just ran efax through those files until I found one it liked:
    efax -d /dev/ttyd4
    efax: Fri Mar 12 13:25:16 2010 efax v 0.9a-001114 Copyright 1999 Ed Casas
    efax: Fri Mar 12 13:25:16 2010 efax v 0.9a-001114 Copyright 1999 Ed Casas
    efax: 25:16 compiled Mar 3 2009 22:24:04
    efax: 25:16 opened /dev/ttyd4
    efax: 25:17 using AEIGPM560LKTF1 AEIGPM560LKTF1 AEIGPM560LKTF1 in class 2
    ^Cefax: 25:19 Error: terminating on signal 2
    efax: 25:19 done, returning 5 (terminated by signal)
  11. Now send it!
    efax -l "+1 555 555 1234" -d /dev/ttyd4 -i "L2 M2" -t 15555555678 fax.g3
    replacing the formatted phone number for -l with your number, the -t argument with the target number, the -d option with your modem's device file, and "fax.g3" with your file's name. You may also have to tweak the modem options in the -i argument.
  12. efax should print out a bunch of progress lines, ending with
    efax: 28:53 done, returning 0 (success)
  13. Call or email the recipient to make sure they got the fax, because you never know.

Wasn't that fun? Hours of work to save me $2! (But, hey, I get to feel proud of myself in that nerdy way, and next time it won't take me as long because I won't have to go through all the trial-and-error to figure this out for the third time.)

No comments:

Labels!