How to read EPUB book using EPUBLIB?
Asked Answered
S

2

5

I found a solution for reading epub books in android using epublib. I am able to read the subtitles of the book. But I didn't find a way to read the line by line of the content. How can I acheive this?

Sample code for getting titles of the book is

  private void logTableOfContents(List<TOCReference> tocReferences, int depth) {
    if (tocReferences == null) {
        return;
    }
    for (TOCReference tocReference : tocReferences) {
        StringBuilder tocString = new StringBuilder();
        StringBuilder tocHref=new StringBuilder();
        for (int i = 0; i < depth; i++) {
            tocString.append("\t");
            tocHref.append("\t");
        }
        tocString.append(tocReference.getTitle());

        tocHref.append(tocReference.getCompleteHref());
        Log.e("Sub Titles", tocString.toString());
        Log.e("Complete href",tocHref.toString());

        //logTableOfContents(tocReference.getChildren(), depth + 1);
    }
}

Got this code from http://www.siegmann.nl/epublib/android

How can I get the story of the book...

Staffman answered 1/7, 2011 at 9:34 Comment(0)
M
7

I'm not sure is that is the way to navigate in epub file. As far as I know (till now - I'm still learning), better way to get all book cocntent is based on spine section. But still - I don't know how to connect this two things (TOC and real spine) with epublib interface. According to documentation: "The spine sections are the sections of the book in the order in which the book should be read. This contrasts with the Table of Contents sections which is an index into the Book's sections."

that is something - if You likie - this is a snippet:

Spine spine = new Spine(book.getTableOfContents());
for (SpineReference bookSection : spine.getSpineReferences()) {
            Resource res = bookSection.getResource();
                try {
                    InputStream is = res.getInputStream();
                    //do something with stream
                } catch (IOException e) {
Mccraw answered 12/7, 2011 at 13:48 Comment(2)
hey thanks....Whats this Spine actually for?? where did i get the documentation for ePubLib....Staffman
how can i found epublib document ?Blaisdell
M
3

Well - i'm not exacly sure about navigating, but also wonder how to do it For now - i have something like this (it is line - by line read):

private void logTableOfContents(List<TOCReference> tocReferences, int depth) {
    if (tocReferences == null) {
        return;
    }
    for (TOCReference tocReference : tocReferences) {
        StringBuilder tocString = new StringBuilder();
        for (int i = 0; i < depth; i++) {
            tocString.append("\t");
        }
        try{
           InputStream is = tocReference.getResource().getInputStream();
           BufferedReader r = new BufferedReader(new InputStreamReader(is));
           String line;
           while ((line = r.readLine()) != null) {
               String line = Html.fromHtml(line).toString();
           }
        }
        catch(IOException e){

        }




        //logTableOfContents(tocReference.getChildren(), depth + 1);
    }
}
Mccraw answered 11/7, 2011 at 13:18 Comment(1)
This reads all of the contents of all TOCReferences at once. I think this harms efficiency.Stencil

© 2022 - 2024 — McMap. All rights reserved.