How do I convert a DjVu document to PDF in Linux using only command line tools?

84,628

Solution 1

djvu2pdf should fit the bill, it's a small script that makes use of the djvulibre toolset. If not, there are other methods that require multiple command-line tools.

Solution 2

The ddjvu program (which is part of the standard djvulibre package) will do this:

$ ddjvu -format=pdf -quality=85 -verbose a.djvu a.pdf

Warning: this produces large files (but PDF files made by Christoph Sieghart's script are of the same size).


I also wrote the following small shell script some years ago.  It does the same automatically. (Save this as djvu2pdf.sh.)

#!/bin/sh

# convert DjVu -> PDF
# usage:  djvu2pdf.sh  <file.djvu>

i="$1"
echo "------------ converting $i to PDF ----------------";
o="$(basename "$i" .djvu).pdf"
echo "[ writing output to $o ] "

ddjvu -format=pdf -quality=85 -verbose "$i" "$o"

The djvu2pdf script by Christoph Sieghart does essentially the same.

Solution 3

What about simply using DJView and export as PDF?

  1. Goto Synaptic Package Manager (System - Administration - Synaptic Package Manager)
  2. Install DJview4
  3. Run DJview (Applications - Graphics - DJView4)
  4. Open your .djvu document
  5. Menu - Export As: PDF

Look at http://art.ubuntuforums.org/showthread.php?t=1232038

Solution 4

$ djvups input.djvu | ps2pdf - output.pdf

In my case the output file was 10x smaller than with ddjvu. Both djvups and ps2pdf present in ubuntu repository.

$ sudo apt-get install djvulibre-bin ghostscript

I've found this method in man ddjvu, so always read manuals ;)

An alternate way to produce PDF file consists in first using djvups(1) and convert the resulting PostScript file to PDF. Which method gives better results depends on the contents of the DJVU file and on the capabilities of the PS to PDF converter.

Solution 5

If you don't care about colors and images you can get much smaller files if you drop the colors and use instead:

ddjvu -format=pdf -mode=black input.djvu output.pdf

Texts, codes and formulas looks perfectly, but most of the images are gone

Share:
84,628

Related videos on Youtube

GeneQ
Author by

GeneQ

I'm not questioning your powers of observation. I'm merely remarking upon the paradox of asking a masked man who he is.

Updated on September 17, 2022

Comments

  • GeneQ
    GeneQ almost 2 years

    I've got some documents in DjVu which I'll like convert to PDF. Is there a way to do this using command line OSS tools?

  • Grzegorz Wierzowiecki
    Grzegorz Wierzowiecki over 12 years
    What's a pity that, currently there is not djvu2pdf tool in Arch repo and old ver in Arch User repo
  • Geremia
    Geremia over 7 years
    Is there a way to make OCR layer of the DjVu come through into the PDF?
  • Plasma
    Plasma about 6 years
    +1 for preserving any text layer in the djvu file
  • Maxim
    Maxim about 5 years
    The question was about using command line only, so this can be automated.
  • Lxrd-AJ
    Lxrd-AJ about 4 years
    Mac users can also run brew install djvu2pdf to install the program and djvu2pdf file.djvu to convert. Homebrew takes care of downloading all its dependencies
  • xdavidliu
    xdavidliu about 4 years
    using ddjvu turned my 6.3 mb djvu file into a 1.7 gig pdf file.
  • Maxim
    Maxim about 4 years
    something is wrong. this should not happen. you can post here the link to the file.
  • Kokizzu
    Kokizzu almost 4 years
    +1 for that apt command XD
  • user313032
    user313032 over 2 years
    This is the only one preserving the text layer. But increases filesize 10-fold for me.
  • Admin
    Admin about 2 years
    djvu2pdf works although it produces a slightly bigger file than ddjvu with compression enabled. Other issue is that it doesn't copy the table of contents of the source document.