Posts Tagged ‘DJVU’

Reading e-books in Linux

May 6, 2008

This post is about how one can read and enjoy their e-books in Linux, covering some of the more popular e-book formats and the software used to view them.

I love books. I love reading them whether they be in tangible (physical bound books) or intangible (electronic) form. Hence my increased infatuation when I discovered the joys of e-books years ago. I don’t have a portable device whose sole purpose is to let me read and view my e-books (since I refuse to carry devices which are built only for a single purpose), but I do have gadgets that do a lot of things, reading e-books included. However, I usually do my e-book reading in my PC/Linux box.

Popular e-book formats

Among the numerous e-book formats, the most prolific (in my opinion) format is PDF. There are many software and applications in Linux which can open and view PDF files, such as KPDF (the one that I use most of the time because it can be used as an embedded pdf viewer in Konqueror), XPDF, and Adobe Reader, among others. Acquiring those into your Linux distribution shouldn’t be a problem. Usually I prefer my e-books to be of PDF type since PDF stores data in vector format and at present, a lot of PDF files are coming out with OCR, which is great but which is not to say that it doesn’t have its cons, but for most reading purposes PDF files come out on top.

Another format is CHM, whose file types can be viewed in Linux using programs such as kchmviewer, and gnochm. I prefer kchmviewer at the moment, since it has a lot of useful features.

Another format which is used more recently is the DJVU format. Linux users can rest assured that DJVU file viewers are available for them, such as Djview, which can also be embedded in Konqueror. There are also browser plug-ins for opening DJVU files.

There are numerous more other e-book viewers such as fbreader which can open fb2 e-book format, Palmdoc, zTxt, TCR, RTF, OEB, OpenReader format and some other formats. One of the new book readers I’m really looking forward to is Okular, the new KDE4 PDF viewer, and also boasts of being able to open also CHM, and DJVU files among others. No need for a lot of separate book viewers.

Lastly, I’ll mention about the LIT book types, which is a proprietary file type by Microsoft. I’m not a big fan of Microsoft but some of the books I get are in .lit format. In order to view those files (or convert them into files already viewable) in Linux, small things need to be done.

Handling LIT files in Linux

A software, Calibre, can be used to open and view HTML, text, RTF, and LRF files, as well as convert LIT files to the former formats, if properly configured. Calibre is a reverse-engineered alternative reader for Sony’s e-reader. Calibre creates a library for your e-books, stored in a self-contained sqlite database format. If you’re an Ubuntu user, you simply do the following to install Calibre in your machine:

Enter the following command and make sure it returns at least a version of 2.5.1

python --version

then afterwards enter these

sudo apt-get install  python-setuptools python-imaging  libqt4-core libqt4-gui \
                      python-qt4 fonttools python-mechanize imagemagick \
                      xdg-utils python-dbus  python-lxml \
                      librsvg2-bin python-genshi help2man
sudo easy_install -U TTFQuery calibre
sudo calibre_postinstall

afterwards you install the tool convert-lit or clit by first installing the libtommath package

sudo dpkg -i libtommath_0.37-1_i386.deb

then finally install clit

sudo dpkg -i clit_1.8-1_i386.deb

Calibre can also be easily installed on other Linux distros such as Gentoo, Debian, and Fedora.

The Convert-lit or clit tool

Convert-lit or clit is the tool that is used by Calibre and all the succeeding software I’ll be mentioning here (in fact, it is the only tool for handling .lit files in Linux at present). Convert-lit or clit has 3 capabilities: The first of the clit command explodes (decompiles) the .lit ebook input file into its constituent HTML file and images which it places in the in an ouput directory. The output directory must already exist. To decompile a .lit e-book:

              mkdir my-ebook; clit my-ebook.lit my-ebook

The second form downconverts the .lit e-book file to a “Sealed” or DRM1 format file. This is useful for reading on handheld devices. To downconvert a .lit e-book:

clit my-ebook-drm5.lit my-ebook-drm1.lit

The third form inscribes the .lit ebook with the given label. To label a .lit e-book:

clit my-ebook-drm5.lit my-ebook-drm1.lit "Title of My-Ebook"

Now you can read your LIT e-books using any application that can open HTML files. If you have a large number of LIT e-books you want to convert, a shell script (which I modified a bit) from a fellow Ubuntu forums user, BobCFC, can be used:

# process every .lit file in the current directory
# use clit to explode each file into directory of same name minus .lit extention
# (optional pass -z argument to create gzip files and remove new directories)
# 2007 RBH

if [ $1 == '-z' ]
        for FILENAME in *.lit
                clit "$FILENAME" "${FILENAME%%.lit}"/
                tar czf "${FILENAME%%.lit}".tar.gz "${FILENAME%%.lit}"
                rm -rf "${FILENAME%%.lit}"
        for FILENAME in *.lit
                clit "$FILENAME" "${FILENAME%%.lit}"/

Save the shell script above in any file name you want, they make it executable by issuing chmod +x filename . The script will extract all the .lit files in the current directory into folders of the same name. Use the -z flag to create compressed gzip files instead.

Compiling clit

For those of you who’ll be needing to compile clit since their distros don’t have clit packages:

– you’ll need the “build-essential” package

– download the clit source file here:
– download the libtommath source code here (make sure that you get the 0.30 version since as of clit version 1.8, clit uses version 0.30 of libtommath and not the latest 0.39 version) :
– Extract the downloaded clit and libtomath files in same directory e.g. enter the commands:

unzip ; tar jxvf ltm-0.30.tar.bz2

cd to the libtommath directory ; issue the command make
cd to clit<version_number>/lib directory; issue again make
cd to clit source directory, clit<version_number>, mine was clit18/

– issue again make – this should use the libtommath built above. You can check to see if you’ve successfully compiled an executable binary file which you can run as clit (assuming there were no error messages after all the make commands you entered) by issuing the command:

file clit

which returns the following in my 64 bit AMD processor:

clit: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), for GNU/Linux 2.6.8, dynamically linked (uses shared libs), not stripped

or the following in my 32 bit AMD processor:

clit: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.8, dynamically linked (uses shared libs), not stripped

Now you can use the clit commands shown above by copying the compiled clit binary file to your bin directory

sudo cp -v clit /usr/bin/

clit in Firefox

If you use Firefox or any of its derivatives, there is an add-on, OpenBerg, which lets you view a number of book formats including comic book archives (.cbr, .cbz) and even .lit files, among others. However, you must have rar, zip, and lit viewer/handler programs already installed in your system/Linux box. The clit setup I mentioned above is just right for allowing OpenBerg to let you view your .lit files. What the add-on actually does is it explodes/converts your .lit books (1st command above) into a browser readable HTML fiile. You have to point OpenBerg to the directory where the clit executable binary file is located, whether you installed it as a package or if you compiled it as shown above, so it can let you view .lit files for you.

Lastly, my personal view is that we should not patronize or encourage the buying and proliferation of any Microsoft format e-books. Let’s allow those formats to be unused or completely forgotten and demand free and open format e-book types such as unencrypted or un-DRMed PDF fiiles, HTML, plain ASCII text files, and others, including Open eBooks. Demand your e-books to be in those formats, open to the scrutiny of the general public. Demand not to be treated as if you were a criminal. Demand to have ridiculous laws like the DMCA repealed. Join the EFF. Let’s not just sit and let Microsoft and other proprietary formats prevent the access of information.

Information is important. And so are books.

Other References

Calibre installation instructions on other Linux distros and OSes

Linux Journal article on converting e-books in Linux

fbreader site