82

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?

studiohack
  • 13,468
  • 19
  • 88
  • 118
GeneQ
  • 4,957
  • 2
  • 36
  • 53

8 Answers8

63

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.

Ramhound
  • 41,734
  • 35
  • 103
  • 130
John T
  • 163,373
  • 27
  • 341
  • 348
  • What's a pity that, currently there is not djvu2pdf tool in [Arch repo](http://www.archlinux.org/packages/?q=djvu2pdf) and old ver in [Arch User repo](http://aur.archlinux.org/packages.php?O=0&K=djvu2pdf&do_Search=Go) – Grzegorz Wierzowiecki Nov 02 '11 at 17:42
  • 1
    Installing `djvulibre-bin` using apt-get and then installing the deb file in that link did the trick. – thameera Apr 21 '14 at 10:27
  • 1
    On mac you `djvu2pdf` is available via [`MacPorts`](http://www.macports.org). – 0 _ Jul 02 '14 at 07:59
  • 6
    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 – Lxrd-AJ Apr 24 '20 at 11:26
  • 1
    `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. – Grwlf May 01 '22 at 11:00
  • `djvu2pdf` works but does not preserve the text layer. It is essentially a wrapper for `ddjvu` and thus running `ddjvu -format=pdf` will produce the same output. For an approach that preserves the text layer see [here](https://superuser.com/a/1806567). – Stefan Schmidt Aug 31 '23 at 11:41
47

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.

Maxim
  • 1,556
  • 12
  • 13
24
$ 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.

raacer
  • 523
  • 4
  • 11
23

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

DMA57361
  • 18,562
  • 7
  • 72
  • 96
toto
  • 247
  • 2
  • 2
12

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

Marcello
  • 121
  • 1
  • 2
3

I've changed the @Maxim script a little ...

#!/bin/bash
# convert DjVu -> PDF
# usage:  djvu2pdf.sh [-q quality | -b] <infile.djvu> [outfile.pdf]

mode='color'
quality=80

aparse() {
  while [ $# != 0 ] ; do
    case "$1" in
    -q|--quality)
      quality=${2}
      shift
      ;;
    -b|--black)
      mode='black'
      ;;
  esac
  shift
done
}
aparse "$@"

i="$1"
o=${2:-$(basename $i .djvu).pdf}
if [ -f  "$o" ]; then 
  echo "file $o exists, override [Y/n]?"
  read ans
  case "$ans" in 
   n|N) exit 1;;
  esac
fi
echo "[ converting $i to $o ] "

cmd="ddjvu -format=pdf -quality=$quality -mode=$mode -verbose $i $o "

echo "[ executing $cmd ] "
$cmd
hute37
  • 101
  • 1
  • 6
2

For MacOS users you can install djvu2pdf like this:

$brew install djvu2pdf 

How to use it(works for any Xnix like system):

$djvu2pdf nameBook.djvu nameBookToCreate.pdf
andreskwan
  • 461
  • 4
  • 4
0

For an approach that preserves the text layer1 one can use djvu2pdf described in this answer. The general approach is described here or here.

For macOS a minor tweak is required.

BSD readlink -f behaviour differs from GNU readlink. This can be fixed by installing GNU coreutuils and changing readlink -f to greadlink -f.


1. According to the description the table of contents will also be preserved, but I haven't tested that.

Stefan Schmidt
  • 623
  • 5
  • 12