How to Create pdf viewer app using Android Studio

First of All thanks for visiting my website, and we are here to share with you one of the most best app which help you to earn money through android studio.
Lets Start :

Step 1 :
First of all create a new project in your Android Studio, and choose Empty Activity

Step 2 :
OK after creating our project in Android Studio, you need to open build.gradle(Module:App) file and
add this library in the dependency section.

implementation 'com.github.barteksc:android-pdf-viewer:3.0.0-beta.5'

Step 3 :
So now open your main_activity.xml and add this line of code

<?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=".MainActivity">


<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/book_pdf"
android:padding="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</RelativeLayout>

Step 4 :
Now open your MainActivity.java first create the object of PDFView and after that add this code.

PDFView book;
int position = -1;
//PDF View
PDFView book = findViewById(R.id.book_pdf); 
position = getIntent().putExtra("position", 
position).getIntExtra("position", -1); 
book.fromAsset("book.pdf") .enableSwipe(true) 
// allows to block changing pages using swipe
// .swipeHorizontal(true)
.enableDoubletap(true)
.defaultPage(0)
.enableAnnotationRendering(false) 
// render annotations (such as comments, colors or forms)
.password(null)
.scrollHandle(new DefaultScrollHandle(this))
.enableAntialiasing(true)
 // improve rendering a little bit on low-res screens
// spacing between pages in dp. To define spacing color, set view background
.spacing(0)
.pageFitPolicy(FitPolicy.WIDTH)
.load();

Step 5 :
Create Asset folder and put pdf file .
follow my instructions please…
now run your app.

That’s it, friends, this is the correct and simple way to create pdf viewer application using android studio. Just follow the above steps and copy paste code carefully at the correct location mentioned above.

if you found this article helpful please do comment below and share the article to support me. if you have any suggestion please feel free to comment below.

Leave a Comment

Your email address will not be published. Required fields are marked *