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

52

27

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?

GeneQ

Posted 2010-01-26T03:20:50.783

Reputation: 4 581

Answers

43

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.

John T

Posted 2010-01-26T03:20:50.783

Reputation: 149 037

On mac you djvu2pdf is available via MacPorts.

– Ioannis Filippidis – 2014-07-02T07:59:31.717

What's a pity that, currently there is not djvu2pdf tool in Arch repo and old ver in Arch User repo

– Grzegorz Wierzowiecki – 2011-11-02T17:42:14.950

Installing djvulibre-bin using apt-get and then installing the deb file in that link did the trick. – thameera – 2014-04-21T10:27:46.593

27

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 bash script some years ago. It does the same automatically. (Save this as djvu2pdf.sh).

#!/bin/bash

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

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

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

The djvu2pdf script by Christoph Sieghart does essentially the same

Maxim

Posted 2010-01-26T03:20:50.783

Reputation: 1 107

2Is there a way to make OCR layer of the DjVu come through into the PDF? – Geremia – 2017-02-25T04:09:56.467

21

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

toto

Posted 2010-01-26T03:20:50.783

Reputation: 227

The question was about using command line only, so this can be automated. – Maxim – 2019-05-19T17:40:54.560

3This is the better and easier solution, thanks! – woohoo – 2012-03-04T02:56:33.137

10

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

Posted 2010-01-26T03:20:50.783

Reputation: 101

8

$ 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

Posted 2010-01-26T03:20:50.783

Reputation: 315

1+1 for preserving any text layer in the djvu file – Plasma – 2018-04-01T18:29:35.677

2

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

Posted 2010-01-26T03:20:50.783

Reputation: 61

1

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

Posted 2010-01-26T03:20:50.783

Reputation: 361