Android PDFView


http://upadhyayjiteshandroid.blogspot.kr/search?updated-min=2015-01-01T00:00:00-08:00&updated-max=2016-01-01T00:00:00-08:00&max-results=1


Android PDFView is a library which provides a fast PDFView component for Android, with animations, gestures, and zoom.

the reference is taken from PDF View.

We just need to use com.joanzapata.pdfview.PDFView at xml layout as follows

<com.joanzapata.pdfview.PDFView
        android:id="@+id/pdfview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>


and than can be used in main activity as follows

pdfView.fromAsset(pdfName)
    .pages(0, 2, 1, 3, 3, 3)
    .defaultPage(1)
    .showMinimap(false)
    .enableSwipe(true)
    .onDraw(onDrawListener)
    .onLoad(onLoadCompleteListener)
    .onPageChange(onPageChangeListener)
    .load();

for a reference here is a full code of

activity_main.xml is as follows


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

    <com.joanzapata.pdfview.PDFView
        android:id="@+id/pdfView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</FrameLayout>

while PDFView can be used in PDFViewActivity as follows

import com.joanzapata.pdfview.PDFView;
import com.joanzapata.pdfview.listener.OnPageChangeListener;

import android.app.Activity;
import android.os.Bundle;

public class PDFViewActivity extends Activity implements OnPageChangeListener {

public static final String SAMPLE_FILE = "sample.pdf";

public static final String ABOUT_FILE = "about.pdf";

PDFView pdfView;

String pdfName = ABOUT_FILE;

Integer pageNumber = 1;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

pdfView = (PDFView) findViewById(R.id.pdfView);
 display(pdfName, false);
}

private void display(String assetFileName, boolean jumpToFirstPage) {
if (jumpToFirstPage)
pageNumber = 1;
setTitle(pdfName = assetFileName);

pdfView.fromAsset(assetFileName).defaultPage(pageNumber)
.onPageChange(this).load();
}

@Override
    public void onPageChanged(int page, int pageCount) {
        pageNumber = page;
     setTitle(pdfName = pageNumber+"");
    }
}


make sure that you have sample pdf files in Asset folder of yours project.

the library code can be downloaded from https://github.com/JoanZapata/android-pdfview  and than PDFViewActivity  can be used simply as in above given  example.

Download code from Demo PDF Activity