1

How to remove spaces and tabs from the text layer in DjVu document for better text search using the DjVuLibre library?

By removing unnecessary characters (and their xml tags), also the file size is reduced.

1 Answer 1

1

First, use the djvutoxml tool to extract a text layer in XML format from the DjVu document.

At the command prompt, type:

path\djvutoxml.exe path\book.djvu path\book.xml

Instead path parameter substitute your location on the disk.

Press Enter...


Then, using the regular expressions, remove the selected characters
(placed between sharp brackets > <). You can use any text editor (that can do regex).

String to remove spaces:

<WORD><CHARACTER coords="\d*,\d*,\d*,\d*"> </CHARACTER></WORD>

String to remove tabs:

<WORD><CHARACTER coords="\d*,\d*,\d*,\d*">&#9;</CHARACTER></WORD>

Regular expression can also be written in this form. This deletes everything at once:

<WORD><CHARACTER coords="([0-9,]*?)">(&#9;| )</CHARACTER></WORD> 

Original fragment:

<WORD coords="318,262,706,190">Hallo</WORD>
<WORD><CHARACTER coords="707,262,760,190"> </CHARACTER></WORD>
<WORD coords="761,262,813,190">World!</WORD>
<WORD><CHARACTER coords="814,262,860,190"> </CHARACTER></WORD>

Fixed fragment:

<WORD coords="318,262,706,190">Hallo</WORD>
[here was the code for the space]
<WORD coords="761,262,813,190">World!</WORD>
[here was the code for the space]

(You can see how large text strings have been removed. Here 62 characters to describe one space!)


Finally, use the djvuxmlparser tool to merge modified XML with DjVu document.

At the command prompt, type:

path\djvuxmlparser.exe -o path\final.djvu path\book.xml

Instead path parameter substitute your location on the disk.
Parameter -o defines the target file.

Press Enter...

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.