printing djvu books under Linux

When I print books, I prefer to have two pages per sheet. With PostScript or PDF books it's easy, I just use psnup2.pl. But for djvu format, the procedure is complicated.

The straightforward way -- convert to PostScript and the rest is known -- doesn't work:

$ djvups book.djvu book.ps
$ psnup2.pl book.ps >book2.ps

Unfortunately, gv can't read the output PostScript file. The tool psnup works correctly only for a subset of PostScript, and djvups generates the code outside this subset.

An usual workaround is to use ps2pdf and pdftops -- we first convert PostScript to PDF and then convert back from PDF to PostScript. But in this case, the workaround works only partially. The output PostScript is very, very big, and gv needs eternity to load it.

After trials and errors, I decided to try TIFF as an intermediate format. And it is the solution.

Well, the simplest way again doesn't work:

$ ddjvu -format=tiff book.djvu book.tiff
Core dump

Instead, I extract page-by-page, ignoring the coredumped ones (fortunately, these pages are not important).

Step 1: get the number of pages

$ djvudump book.djvu | head
...
    DIRM [2733]       Document directory (bundled, 354 files 350 pages)
...

Step 2: write the page extraction script gen.pl.


foreach my $i (1...350) {
  printf "ddjvu -format=tiff --page=%i book.djvu pages/p%03i.tif\n", $i, $i;
}

Step 3: extract pages

$ mkdir pages
$ perl gen.pl >x.sh
$ sh x.sh
.. ignore core dumps ...

Step 4: create PostScript from TIFF


$ tiff2ps -w 8.27 -h 11.69 -c pages/p???.tif >print.ps

Step 5: make two pages per sheet:

$ psnup2.pl print.ps >print2.ps

Step 6: print!

Categories: publishing

Updated: