How to read an EPUB book using EPUBLIB?

I found a solution for reading epub books in android using epublib. I can read subtitles of a book. But I did not find a way to read line by line of content. How can I understand that?

Sample code for getting book titles

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 a story about a book ...

+5
source share
3 answers

I'm not sure if this is the way to navigate in an epub file. As far as I know (so far - I was still studying), the best way to get the whole book is based on a section of the spine. But still - I do not know how to connect these two things (TOC and the real spine) with the epublib interface. According to the documentation: "Spine sections are sections of a book in the order the book should be read. This contrasts with the sections" Content ", which is an index in the" Books "section.

this is something - if you are alike - 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) { 
+7
source

Well, I'm not sure about navigation, but I'm wondering how to do it. At the moment - I have something like this (this is line by line):

 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); } } 
+3
source

I am trying to read all the text in an epub file in line with this code, but it does not work! How can i do this?

 package com.mahdi.File_Reader; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.List; import java.util.jar.JarFile; import android.app.Activity; import android.content.res.AssetManager; import android.content.res.Resources; import android.os.Bundle; import android.text.Html; import android.util.Log; import android.widget.AnalogClock; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import com.mahdi.File_Reader.jchmlib.*; import nl.siegmann.epublib.*; import nl.siegmann.epublib.domain.Book; import nl.siegmann.epublib.domain.TOCReference; import nl.siegmann.epublib.epub.EpubReader; public class File_ReaderActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView tv1 = (TextView) findViewById(R.id.textView1); AssetManager assetManager = getAssets(); InputStream inputStream; try { inputStream = assetManager.open("xxx.epub"); Book ebook = new EpubReader().readEpub(inputStream); tv1.setText(logTableOfContents(ebook.getTableOfContents().getTocReferences(), 0)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private String logTableOfContents(List<TOCReference> tocReferences, int depth) { String lineXX="p"; if (tocReferences == null) { return "d"; } 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 lineX = Html.fromHtml(line).toString(); lineXX=lineX; } } catch (IOException e) { lineXX="X"; } // logTableOfContents(tocReference.getChildren(), depth + 1); } return lineXX; } 

}

+2
source

Source: https://habr.com/ru/post/906526/


All Articles