Skip to content

HamedTaherpour/ht-epub-reader-android

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTePubReader

ePub reader and parser library for android

Demo

Build

step 1. Add the JitPack repository to your build file

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

step 2. Add the dependency

dependencies {
    implementation 'com.github.HamedTaherpour:ht-epub-reader-android:0.0.5'
}

Usage

Manifest

step 1. Add permission your manifest file

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Layout.xml

step 2. Add EpubView to xml code

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:cardElevation="3dp">

    <io.hamed.htepubreadr.ui.view.EpubView
        android:id="@+id/epub_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="10dp" />

</androidx.cardview.widget.CardView>

Java

step 3. Create EpubReaderComponent and fetch ePub data

try {
    EpubReaderComponent epubReader = new EpubReaderComponent(filePath);
    BookEntity bookEntity = epubReader.make(this);
} catch (Exception ex) {
    ex.printStackTrace();
}

BookEntity

get all page path

List<String> allPage = bookEntity.getPagePathList();

get book name

String bookName = bookEntity.getName();

get author name

String authorName = bookEntity.getAuthor();

get Cover image

String coverImage = bookEntity.getCoverImage();

get Sub Book Href (path from local file)

List<SubBookEntity> allPage = bookEntity.getSubBookHref();

setUp EpubView

// set file path
epubView.setBaseUrl(epubReader.getAbsolutePath());
String content = EpubUtil.getHtmlContent(allPage.get(position));
epubView.setUp(content);

set font see sample css file

FontEntity fontEntity = new FontEntity(url,name);
epubView.setFont(fontEntity);

set font size

epubView.setFontSize(15);

on hyper link click listener

epubView.setOnHrefClickListener(new OnHrefClickListener() {
    @Override
    public void onClick(String href) {

    }
});