Epublib – a java epub library

Epublib is a java library for managing epub files. It’s capable of reading and writing epub files programmatically and from the command-line tool.

Epublib is a library that comes with a command-line tool as well. It’s intended use is both as part of a larger java application and as a command-line tool.

Features

  • epublib-core runs on Android
    Epublib consists of 2 parts: core and tools.
    Tools require a standard java environment.
    The core runs both on Android and a standard JVM.
  • Builtin viewer
  • Comprehensive coverage of the epub standard
  • Simple things are simple
    The api is designed to be as simple as possible, while at the same time making complex things possible too.
    [sourcecode language="java" gutter="false" wraplines="true"]
    // read epub
    EpubReader epubReader = new EpubReader();
    Book book = epubReader.readEpub(new FileInputStream("mybook.epub"));

    // set title
    book.getMetadata().setTitles(new ArrayList<String>() {{ add("an awesome book");}});

    // write epub
    EpubWriter epubWriter = new EpubWriter();
    epubWriter.write(book, new FileOutputStream("mynewbook.epub"));

    [/sourcecode]

  • Cleans up html into xhtml
    Does not remove non-standard tags and attributes, but makes html files into valid xml (using xmlcleaner http://htmlcleaner.sourceforge.net/)
  • Cleans up non-standards compliant epub
    Epublib tries to be as forgiving as possible when reading epubs and writes them as standards-compliant as possible.
    If you’ve created an epub by zipping up several html files then running it through epub will make it much more standards-compliant.
  • Fixes the coverpage on many readers
    For different epub readers the coverpage needs to be specified in a different way. Epublib tries several ways of extracting the coverpage from an existing epub and writes it in such a way that most (all the readers I’ve tested it on) display the coverpage correctly.
  • Support for creation of epubs
    The api supports the creation of epubs from scratch. See Creating a simple book example for an example.
  • Convert (uncompressed) windows help (.chm)  files to epub
    After uncompressing a windows help file with something like chmlib epublib can make an epub file out of the resulting html and windows help index files