7

How can I convert PNG to DjVu? I only know how to convert JPEG or PPM to DjVu using DjVuLibre. I'm using Windows 8.1.

  • 2
    Which operating system (it may affect the answers)? – Jason Down Feb 16 '14 at 15:31
  • I'm using windows 8.1. – hans-t Feb 16 '14 at 15:36
4

PNG and DjVu are complementary formats as PNG is lossless and DjVu is lossy. DjVu's effectiveness in storing information is the result of using high quality compression and splitting a single image into multiple layers which essentially employ different compression algorithms.

As you indicate, you already know how to convert JPEG or PPM to DjVu, so the simple answer is convert your PNG to either JPEG or PPM and use that as an input for you known conversion. These can be considered different routes to obtaining a DjVu file because they store data in different layers, and they don't generate the same output (in quality and compression).

Hazzit's answer is correct for monochrome images, as it first converts the PNG to a bitonal (black & white) image that is then, using cjb2, stored in the bitonal layer of a DjVu file. With the --clean option cjb2 does only minimal lossy compression, but if you start out with a multicolor PNG (such as a photo), you will have lost most of the information in the conversion to a bitonal image.

Low color PNG images can be converted first to .ppm (you can do this with the ImageMagick as in Hazzit's answer as well by specifying a .ppm output file name instead of a .pbm) and then use cpaldjvu. This program does simple quantization, and stores this information into multiple layers.

If your PNG has many colors (like in a photo) you will have better results converting the PNG file to JPEG (again with convert and a .jpg output file) and then use that to convert to DjVu. You can e.g. print/convert the PNG to PostScript and use that as input to pdf2djvu that is part of DjVuLibre. The resulting image data is compressed using Wavelet compression and stored in a different layer from the bitonal one mentioned in the previous example.

What route to take depends on the contents of the input file format and the required result, far more than it does on being a PNG file. Especially with the DjVuLibre tools no boilerplate answer can be given, as they do not help you determine what compression is best for the image you provide. You implicitly do that by selecting the conversion program (cjb2, cpaldjvu etc).

In my experience the DjVuLibre—as a reference implementation—generates correct DjVu files, but it doesn't employ the best compression techniques to generate the output. You might want to look at a converter that is not based on DjVuLibre, if resulting compression ratio and/or image quality is important. You can use any2djvu to do an online conversion, or one of the other online conversion tools. They do a better analysis of the images to determine what is the best way to compress your image (i.e. what goes in what layer). You can freely experiment with those, but of course you don't know what happens with your data. The commercial Document Express Editor also does a better job, (originally from LizardTech, who also released the DjVuLibre as open source), which was for some time available from Caminova and now possible from Cuminas

  • Thanks for your comprehensive answer. I'll try your method. – hans-t Feb 18 '14 at 16:07
1

There is a Wikipedia help page on that subject. Apart from DjVuLibre you will need ImageMagick

Step 1: Convert PNG to PBM using ImageMagick's convert utility:

convert myfile.png tempfile.pbm

Step 2: Convert PBM to DJVU using DjVuLibre's cjb2 utility:

cjb2 -clean tempfile.pbm myfile.djvu
  • The method is difficult, as you must convert the image one by one. – hans-t Feb 18 '14 at 16:06
  • @user74158 Batch files do exist. – Hazzit Feb 19 '14 at 3:26
0

An interesting option is Jakub Wilk's didjvu, but it is not available on Windows. I don't think the program contains anything Linux specific, just the author doesn't use Windows. Perhaps a user will port it to Windows, as it happened with pdf2djvu.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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