android studio pdf viewer Tutorial

Add to build.gradle:

implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'


Include PDFView in your layout

<com.github.barteksc.pdfviewer.PDFView    android:id="@+id/pdfView"    android:layout_width="match_parent"    android:layout_height="match_parent" />

Load a PDF file

private PDFView pdfView;
pdfView = findViewById(;
pdfView.fromAsset("filename") .enableSwipe(true) .swipeHorizontal(true) .enableDoubletap(true) .defaultPage(0) .enableAnnotationRendering(false) .password(null) .scrollHandle(null) .enableAntialiasing(true) .spacing(0) .pageFitPolicy(FitPolicy.WIDTH) .load();At Create Folder (assets ).Paste the PDF here...

Taking a deep look into the code above

filename is a place holder for the pdf file you uploaded. Input the name without the extension (.pdf)


This allows you to changing pages using swipe


Allows you to swipe left and right horizontally


This can be set to true if you want to render annotations such as colors, comments forms etc but in my case i disabled it by setting the value to false


As you might have thought of this determines the space in between pages measured in dp. To make it more obvious set view background which will make you see the spacing color


Related Articles

Leave a Reply

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

Back to top button *