Android PdfViewer


 1. Add to build.gradle:

compile 'com.github.barteksc:android-pdf-viewer:2.8.1'



2. Add assets folder


3.main_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.arham.csdevbin.pdfdomo.MainActivity">
<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/pdfView"
android:layout_width="match_parent"
android:layout_height="500dp"
android:layout_marginTop="8dp">
</com.github.barteksc.pdfviewer.PDFView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:weightSum="1">
<Button
android:id="@+id/nextBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:onClick="nextPage"
android:text="Next" />
<Button
android:id="@+id/prevBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_weight=".25"
android:onClick="prevPage"
android:text="Prev" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:onClick="zoomIn"
android:text="Zoom in" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:onClick="zoomOut"
android:text="zoom out" />
</LinearLayout>
</RelativeLayout>
package com.arham.csdevbin.pdfdomo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import com.github.barteksc.pdfviewer.PDFView;
public class MainActivity extends AppCompatActivity {
public PDFView pdfView;
public float zoomValue = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pdfView = (PDFView) findViewById(R.id.pdfView);
pdfView.fromAsset("kitab_at_tawheed.pdf")
// .spacing(10)
.enableSwipe(true) // allows to block changing pages using swipe
.swipeHorizontal(true)
.enableDoubletap(true)
.defaultPage(0)
.load();
}
public void nextPage(View view) {
pdfView.jumpTo(pdfView.getCurrentPage() + 1, true);
}
public void prevPage(View view) {
pdfView.jumpTo(pdfView.getCurrentPage() - 1, true);
}
public void zoomIn(View view) {
++zoomValue;
pdfView.zoomTo(zoomValue);
pdfView.loadPages();
}
public void zoomOut(View view) {
if (zoomValue != 1) {
--zoomValue;
pdfView.zoomTo(zoomValue);
pdfView.loadPages();
}
}
}

Comments :

Post a Comment