Converting documents to Palm Doc format

I recently acquired a Handspring Visor, a wonderful little device that runs the PalmOS. Being a long-time Dickens fan, I went over to Memoware to see what was available. Alas, very little, outside of the standard Dickens stuff (A Christmas Carol, Tale of Two Cities, Oliver Twist, etc.)

So, I set myself to figure out how to convert stuff for myself. After a few dead ends, I discovered txt2pdbdoc by Paul Jay Lucas. It's a Unix utility, which, as the name suggests, converts a txt file to a doc file.

I've gotten this down to a science, and am churning out 2 or 3 of these a day, mostly while I'm waiting on hold, or other wasted time.

Here's the procedure:

  1. Get the document from the Gutenberg Project
  2. In your favorite text editor, split the file into smaller pieces, if necessary. This is done because it is nice to keep the Doc files small, due to the limited memory available on the handheld. What I recommend is putting the Project Gutenberg information into one file, and then splitting the rest of the file up into chunks that are 100K or less. I typically put 5 chapters into one file, if that is convenient. I name these files BookTitle00.txt, BookTitle01.txt, BookTitle02.txt, and so on. This is the most time-consuming step.
  3. Put these files into a directory on your Unix machine, where you have txt2pdbdoc installed. If you created the files on a Windows machine, make sure that you transfer them in ascii mode!
  4. Use txt2pdbdoc to convert the files to doc format. This is where Perl comes in handy, since you will be typing essentially the same command line for every file. So, let Perl do it for you. At the command line, type the following:
    perl -e 'for(0..4){$_=sprintf"%.2d",$_;`txt2pdbdoc "Book Title $_" BookTitle$_.txt BookTitle$_.pdb`;}'
    
    Of course, replace 4 with the maximum file number that you have, "Book Title" with the title that you want to appear on each file, and BookTitle with the name that you gave to the files in step 2.

    Now, after typing that command line a dozen times or so, it gets a little tedious, so you can just use the following Perl program:

    #!/usr/bin/perl
    $max = $ARGV[0];
    $title = $ARGV[1];
    $filename = $ARGV[2];
    
    &usage unless $filename;
    
    for $x (0..$max)        {
            $x = sprintf "%.2d", $x;
            `txt2pdbdoc \"$title $x\" $filename$x.txt $filename$x.pdb`;
    }
    
    sub usage {
    print "Usage: pdb_batch no_of_files \"Title\" filename_prefix\n\n";
    exit(0);
    }
    
    Call it pdb_batch and throw it in /usr/local/bin or somewhere else in your path. You can then call it as shown in the example below:
    pdb_batch 4 "Book Title" BookTitle
    
  5. OK, now you have your pdb files. Create a text file saying what is in each of the pdb files. This takes an additional 10 seconds, an dis greatly appreciated by the person that downloads your file. This will look something like:
    Hard Times
    Charles Dickens
    
    HardTimes00.pdb - Project Gutenberg information
    This first file *must* be included in any redistribution of
    these files!
    HardTimes01.pdb - Chapters 01-05
    HardTimes02.pdb - Chapters 06-10
    etc ...
    
Please let me know if these tips were at all helpful. You can send me email at PalmDocs@RCBowen.com