Home > Digital Libraries, recipes > Converting DjVu to PDF

Converting DjVu to PDF

December 8th, 2006

Ok, so say you have a bunch of bundled djvu files. djvu has many advantages over pdf in quality and size, but you just can’t beat pdf for it’s ubiquity. The djvu viewer on the mac is pretty flaky too. My latest problem with it is that the djvu looks stunning on screen but looks fuzzy when printed. For a project we have here, students needed to print the djvu files of musical scores so they could easily reference the hard copy whileentering the notation in Finale. That’s the setup. Using a couple of open source tools and some php glue, here’s a quick solution to batch conversion of djvu to pdf. You need the djvulibre tools and imagemagick. You also need some bundled djvu files.

Here’s the script: It uses lots of execs, so it’s probably not something you want to be run by the public. I run this through the command-line and then pass the output to bash. Using print statements instead of execs lets me run the commands individually if I want to test them out and see any errors. Using an exec will work as well if you’re confident that you don’t have any weird djvu’s in your list

Usage: php4 convert.php |sh

$file = $argv[1];
$file = $file . ".djvu";
$stem = ereg_replace(".djvu", "", $file);
$pages = exec("djvudump $file |grep INFO |wc -l");

for ($i = 1; $i <= $pages; $i++)
{
print "ddjvu -page=$i -format=tiff $file $stem-$i.tiffn";
$pdf_string = $pdf_string . " $stem-$i.tiff";
}
print "convert -adjoin $pdf_string -format pdf $stem.pdfn";
print "rm *.tiffn";

Categories: Digital Libraries, recipes Tags:
Comments are closed.