52

I want to convert a DJVU document into a PDF document, separating and preserving the text layer and the images while also keeping the structure from the DJVU. How can I do this in Ubuntu?

(I will then be using Calibre to convert to ePub/Mobi, so if there were a Calibre plug-in for this entire process that would be perfect for me!)

Note1: Printing from Evince, exporting from DJview, or anything using the package ddjvu, are not adequate solutions as they discard the text layer, saving only images.

Note2: Using DJVULibre seems to only extract the text layer and pictures are not extracted. Similarly, copying the text "manually" loses the both document structure and the pictures.

1

7 Answers 7

46

Method 1

Simply use DJView and export as PDF

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

Method 2

Open the djvu file in evince
Select print ----> print to file
change .ps to .pdf and click print

Method 3

  1. Goto Synaptic Package Manager
  2. Install

    djvulibre-bin libdjvulibre21 okular-extra-backends evince libevdocument3 libevview3

  3. Goto terminal and write

     sudo apt-get install libtiff-tools
    
  4. Goto the directory where the djvu file is present. Click the right mouse button. Goto “Open In Terminal” option. Click on it. A terminal will open.

  5. In that terminal write

    ddjvu -format=tiff file_name.djvu file_name.tiff
    tiff2pdf -j -o file_name.pdf file_name.tiff
    

Method 4

There is also an online converter DjVu to PDF converter

8
  • @Ashu Are you sure this retrieves the pictures?
    – hayd
    Apr 17, 2012 at 9:52
  • Yeah method 1 and 2 did work for me . didnt try for 3 and .4
    – Ashu
    Apr 17, 2012 at 10:30
  • 3
    It doesn't (retrieve the images or text).
    – hayd
    Aug 16, 2012 at 9:47
  • 2
    About "Method 2": changing the extension from .ps to .pdf does not change anything, Evince still produces the same Postscript file (tested on Ubuntu 17.10).
    – Alexey
    Jan 8, 2018 at 5:01
  • 2
    The text layer is lost with method 1 (i suppose with the others too).
    – Alexey
    Jul 28, 2019 at 9:19
23
+200

Here is one way, which would require some not so common tools:

  1. ocrodjvu
  2. pdfbeads, that has it's own requirements which can be found by Google

We can use djvu2hocr command (from ocrodjvu package) to extract hidden text layer from DjVu file (it doesn't do any OCR or similar, it just extracts text layer with geometry), i.e.:

djvu2hocr -p 10 sample.djvu | sed 's/ocrx/ocr/g' > pg10.html

sed intervention corrects class names in output hOCR (which is just simple HTML file)

Now we extract DjVu page to TIFF format with:

ddjvu -format=tiff -page=10 sample.djvu pg10.tif

so that we end with these file in out work folder:

sample.djvu
pg10.html
pg10.tif

This is where pdfbeads comes in play, and we simple execute:

pdfbeads -o pg10.pdf

then this nifty program takes care of everything that's inside this folder (HTML and TIFF files with same base name) and produces output PDF file with some by-products:

sample.djvu
pg10.html
pg10.tif
pg10.jbig2
pg10.pdf
pg10.sym

which is identical to input DjVu file and has text layer inside:

enter image description here

Comments summary:

Lengthy comments below discuss representing smaller images from DjVu document page as separate objects, which is not easily possible because DjVu document page is itself just a single image with optional text layer, with no "information" about smaller images as separate objects. If DjVu document has color images, then they'll be usually placed on background layer; in this case user can take advantage of tools like ddjvu (extract only background layer) and imagemagick (auto-crop) to output just images instead whole canvas, but it can't be automated for creating PDF output

Another saner, but slower approach is use of regular OCR GUI tools. gscan2pdf (> 1.0) is suggested as possible candidate for Linux PC

18
  • Am I correct in thinking that this doesn't extract the individual picture data, but only the image of the entire page?
    – hayd
    Apr 17, 2012 at 14:44
  • What do you mean by "individual picture data" when you refer to DjVu file structure?
    – zetah
    Apr 17, 2012 at 15:32
  • whether it can crop the pictures out of the document as smaller images placed on top of the PDF (e.g. so they could export to HTML)
    – hayd
    Apr 18, 2012 at 15:59
  • There is no such definition in DjVu file structure. Above example image in original DjVu document is "placed" on foreground layer/mask together with characters image and there is separate text layer which was extracted as explained. If DjVu document has color image(s) they will be placed on background layer across whole page (in common compound DjVu file). While it's understandable that you may expect that images in DjVu document page are separate objects they are not - look at DjVU document page as single image with optional text layer, that's basically what is it.
    – zetah
    Apr 18, 2012 at 16:33
  • 1
    @zetah - the extra information you have given in the comments should really be added to the answer because it provides valuable information as to picture placement in the structure and what you would expect when extracting.
    – fossfreedom
    Apr 19, 2012 at 11:22
6

There is djvu2pdf but it relies on ghostscript so it might be another printing option. I still suggest you give it a look, just in case it's more clever than I'm giving it credit.

It's not in the repos but you can download a deb from the makers' site: http://0x2a.at/s/projects/djvu2pdf

** Insert mandatory notice about downloading/installing things from outside the repos here **

2
  • 1
    I'm afraid djvu2pdf uses ddjvu to export to PDF, which exports images without text.
    – hayd
    May 31, 2011 at 16:59
  • brew install djvu2pdf
    – HappyFace
    Sep 21, 2020 at 17:58
4

Using DJVULibre, one can extract the text layer via the terminal command:

djvutxt myfile.djvu > myfile-ocr.txt or djvused myfile.djvu -e 'print-pure-txt' > myfile.txt

(both do the same thing, and were found here)

Formatting requires some effort (as many symbols are not converted properly) and pictures are not recovered.

1
  • This is good for converting picture-less books in DJVU format, but not for documents with pictures. This is the current solution for me at the moment, and the only one to extract the text. A way to preserve formatting and pictures would be much preferred!
    – hayd
    Jun 6, 2011 at 13:43
2

I made a script of @zetah's answer.

It is available here: https://gist.github.com/matthieuheitz/7287e214b1aeda7948f6c27fbfb5288b

1
  • Very good summary of what is in that post. Thanks for this script!
    – rbrito
    May 15, 2020 at 4:46
0

http://www.djvu-pdf.com/ - Using this website you can convert djvu to pdf.

2
  • i have already posted that website bro
    – Ashu
    Apr 17, 2012 at 12:06
  • This seems a fake site. I get this message after conversion: I'm sorry, you may not download that file.
    – corev
    Oct 9, 2012 at 4:44
0

The easiest way: use gscan2pdf to import the djvu, then OCR it with tesseract, and finally save it as a pdf. The OCR'd text in the pdf might be slightly different from the original djvu, and the conversion may take a while, but this method is a no-brainer and it works.

1
  • 1
    Hi, to make this a more useful anwer could you give a little more detail about where to obtain and use gscan2pdf and tesseract.
    – NGRhodes
    Apr 12, 2015 at 22:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .