Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question

5 Answers 5

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 **

share|improve this answer
1  
I'm afraid djvu2pdf uses ddjvu to export to PDF, which exports images without text. –  hayd May 31 '11 at 16:59

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.

share|improve this answer
    
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 '11 at 13:43

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

share|improve this answer
    
@Ashu Are you sure this retrieves the pictures? –  hayd Apr 17 '12 at 9:52
    
Yeah method 1 and 2 did work for me . didnt try for 3 and .4 –  Ashu Apr 17 '12 at 10:30
    
@Ashu is it extracting the pictures or simply copying the entire page? (does that make sense?) –  hayd Apr 17 '12 at 14:45
    
Did you try any method? try it out and see if it works –  Ashu Apr 18 '12 at 4:21
    
It doesn't (retrieve the images or text). –  hayd Aug 16 '12 at 9:47

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

share|improve this answer
    
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 '12 at 14:44
    
What do you mean by "individual picture data" when you refer to DjVu file structure? –  zetah Apr 17 '12 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 '12 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 '12 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 '12 at 11:22

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

share|improve this answer
    
i have already posted that website bro –  Ashu Apr 17 '12 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 '12 at 4:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.