4

I have a djvu book that has different sized pages. How can I solve this by making all pages to same size. I am familiar with Python programming and I'm ready to try it. Any advise is appreciated.

1

2
  • Should the "smaller" pages be scaled, or just displayed on a larger canvas without scaling? Do you have an example file (of a few pages)? What platform do you work on (i.e. can you run the common DjVu tools available on linux)?
    – Anthon
    Commented Jul 18, 2017 at 17:10
  • Yes I would like the smaller page to be scaled. drive.google.com/file/d/0Byj8JxXAeyj_OXU1WGk0QlNDcGc/… I work on Windows 10 64 bit Commented Jul 18, 2017 at 22:19

2 Answers 2

3

As all pages are having the same or very similar width and height, this seems a "simple" problem of some pages having the wrong resolution. Most pages have metadata that specifies 600 DPI others only 96 DPI. That later are then of course displayed much larger.

My Linux distribution comes with djvutoxml and the corresponding djvuxmlparser (from package djuvlibre-bin) which can extract the metadata, resp. merge the metadata back in. Those should be available for Windows as well (http://djvu.sourceforge.net/, make sure the executables are in your PATH) That metadata includes the DPI information from the file. Actual changing of the XML is fast, but extracting and merging takes a long (several minutes) time.

Make sure you have a copy of your book, in case the merging breaks something, and run python program.py book.djvu on this program.py:

import sys
import subprocess

book = sys.argv[1]
xml_in = 'in.xml'
xml_out = 'out.xml'

print('extracting XML')
subprocess.check_output(['djvutoxml', book, xml_in])

print('converting XML')
with open(xml_in) as inf:
    with open(xml_out, 'w') as outf:
        for line in inf:
            if line.startswith('<PARAM name="DPI" value="96" />'):
                line = line.replace('96', '600')
            outf.write(line)
print('merging XML')
subprocess.check_output(['djvuxmlparser', '-o', book, xml_out])

print('done')

In general I am against parsing XML without a real parser, but you don't need regex or anything that easily breaks to get this information fixed.

The intermediate XML (two files) has the same order of size as the DjVu file itself, although the XML has no image information, it is just inefficient. Make sure you have enough room (and run this program on a fast/local drive)

There are 367 incorrect pages out of 1201, you might be able to speed up the process by only including the incorrect pages in the output XML, but then you should use an XML parser. If this is a one off conversion, I would not bother with such an optimisation.

2
  • I'm sorry. I do have python. I quite lost you from the "Those should be available for Windows as well (djvu.sourceforge.net, make sure the executables are in your PATH)". Could you please give me a detailed explanation of steps on this, I do have python (2.7 & > 3.0). I would like to do this and probably make an app so that others can benefit too. Commented Aug 11, 2017 at 16:55
  • Sorry, but I seriously doubt that you can make an app out of this if you don't have the basic understanding of why it is necessary. Apart from that you would have to adhere to the copyrights of djvuxmlparser and djvutoxml. Contact me via email so I have a return email address and I can sent you a link to the converted document, which AFAICT is copyrighted as well.
    – Anthon
    Commented Aug 11, 2017 at 17:59
0

If you want to try to make all your kindle reader there's other easy way around. try K2pdfopt it will help you resizing all pages to a specific screen size.

2
  • I din't quite understand what you are trying to say. Are you saying you want to batch process the djvu file to kindle format so that it automatically has specific screen size all over it ? Commented Aug 11, 2017 at 17:09
  • @abhilashsukumari Yes that's the idea. Not just kindle format but to any other eBook reader format of choice. K2pdfopt supports many.
    – v_sukt
    Commented Aug 11, 2017 at 23:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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