2

i'm working on an application in which i want to read epub file page by page using epublib and show in a app , i am able to get all contents of book chapter wise , now i want to get contents page wise , plz answer if you have any idea , thanks in advance

here is code that i used for getting contents of book chapter wise

    public String getText(String filepath) {

    String linez = "";
    File f = new File(filepath);

    InputStream epubInputStream = null;
    try {
        epubInputStream = new FileInputStream(f);
    } catch (FileNotFoundException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }

    Book book = null;
    try {
        book = (new EpubReader()).readEpub(epubInputStream);
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    Spine spine = book.getSpine();
    List<SpineReference> spineList = spine.getSpineReferences();
    int count = spineList.size();
    txtpages.setText("Size:" + Integer.toString(count) + "\n");
    StringBuilder string = new StringBuilder();
    for (int i = 0; count > i; i++) {
        Resource res = spine.getResource(i);

        try {
            InputStream is = res.getInputStream();
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(is));
            try {
                while ((line = reader.readLine()) != null) {
                    linez = string.append(line + "\n").toString();
                }

            } catch (IOException e) {
                e.printStackTrace();
            }

            // do something with stream
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    //webView.loadData(linez, "text/html", "utf-8");


    return linez;
}
Waynn Lue
  • 11,344
  • 8
  • 51
  • 76
Farhan Munir
  • 409
  • 5
  • 23

1 Answers1

0

You may able to seperate an epub file page by page by using EpubParser. Even though it still has some issues it does its job.

starkm
  • 859
  • 1
  • 10
  • 21