Convert djvu to pdf

conversiondjvupdf

How to convert djvu2pdf ?

My current approach is :

djvups x.djvu > x.ps
ps2pdf x.ps

Is there more efficient and better (in terms of output quality, data/metadata loss) way to handle that ?

Best Answer

I tried printing the djvu file to PDF (using Evince, so it's probably a mix of djvulibre, gtk+ and cairo), but I got a way smaller result by converting the djvu pages to pdf using ImageMagick's convert.

For this, you need to

  1. extract each page as a separate djvu document (I'm not sure if convert is able to deal multipage djvu and multipage pdf that easily), see djvmcvt -i (an "indirect" document is a document where each page is stored in a separate djvu file)
  2. convert the page using convert — we're not losing anything here, remember that djvu is not vectorial, so even if you're generating an Adobe PDF, you're using it for a raster image
  3. join the pages in a single PDF (you can just feed them to ghostscript -- for example, generating an A4 PDF named out.pdf with all pages from *.pdf in the current directory would be gs -q -sPAPERSIZE=a4 -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=out.pdf *.pdf)

This said, keep in mind that

  • This does just a straight conversion of a raster image — I guess the only thing you can tweak is the image quality, if it gets stored in the pdf using lossy compression (if convert is unable to do that, ghostscript has some options to tweak the output of pdfwrite, along the lines of -dPDFSETTINGS=, I'm not sure but these may include the possibility of enforcing lossy compression and defining the quality level)

  • This does not use djvu-specific knowledge, I guess the fact djvu encodes foreground and background separately can be used to generate the PDF in a clever way that somehow uses that to save some space

  • PDF is for vectorial stuff, djvu is way better suited for rasterized documents than PDF.

Related Question