You can download the source from here(Display PDF file inside my android application)

Add this dependency in your gradle file:

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

activity_main.xml

<RelativeLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    xmlns:android="http://schemas.android.com/apk/res/android" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="@color/colorPrimaryDark"
        android:text="View PDF"
        android:textColor="#ffffff"
        android:id="@+id/tv_header"
        android:textSize="18dp"
        android:gravity="center"></TextView>

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


    </RelativeLayout>

MainActivity.java

package pdfviewer.pdfviewer;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import com.github.barteksc.pdfviewer.PDFView;
import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener;
import com.github.barteksc.pdfviewer.listener.OnPageChangeListener;
import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle;
import com.shockwave.pdfium.PdfDocument;

import java.util.List;

public class MainActivity extends Activity implements OnPageChangeListener,OnLoadCompleteListener{
    private static final String TAG = MainActivity.class.getSimpleName();
    public static final String SAMPLE_FILE = "android_tutorial.pdf";
    PDFView pdfView;
    Integer pageNumber = 0;
    String pdfFileName;

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


        pdfView= (PDFView)findViewById(R.id.pdfView);
        displayFromAsset(SAMPLE_FILE);
    }

    private void displayFromAsset(String assetFileName) {
        pdfFileName = assetFileName;

        pdfView.fromAsset(SAMPLE_FILE)
                .defaultPage(pageNumber)
                .enableSwipe(true)

                .swipeHorizontal(false)
                .onPageChange(this)
                .enableAnnotationRendering(true)
                .onLoad(this)
                .scrollHandle(new DefaultScrollHandle(this))
                .load();
    }


    @Override
    public void onPageChanged(int page, int pageCount) {
        pageNumber = page;
        setTitle(String.format("%s %s / %s", pdfFileName, page + 1, pageCount));
    }


    @Override
    public void loadComplete(int nbPages) {
        PdfDocument.Meta meta = pdfView.getDocumentMeta();
        printBookmarksTree(pdfView.getTableOfContents(), "-");

    }

    public void printBookmarksTree(List<PdfDocument.Bookmark> tree, String sep) {
        for (PdfDocument.Bookmark b : tree) {

            Log.e(TAG, String.format("%s %s, p %d", sep, b.getTitle(), b.getPageIdx()));

            if (b.hasChildren()) {
                printBookmarksTree(b.getChildren(), sep + "-");
            }
        }
    }

}
Answer from Deepshikha Puri on Stack Overflow
🌐
Android Developers
developer.android.com › camera & media dev center › implement a pdf viewer
Implement a PDF viewer | Android media | Android Developers
November 17, 2025 - To incorporate the PDF viewer into your application, declare the androidx.pdf dependency in your app's module build.gradle file. The PDF library is accessible from the Google Maven repository. dependencies { val pdfVersion = "1.0.0-alpha0X" ...
🌐
Android Developers
developer.android.com › core areas › ui › views › implement a pdf viewer
Implement a PDF viewer | Views | Android Developers
To incorporate the PDF viewer into your application, declare the androidx.pdf dependency in your app's module build.gradle file. The PDF library is accessible from the Google Maven repository. dependencies { val pdfVersion = "1.0.0-alpha0X" ...
Discussions

Android-Code to Implement PDF Viewer - Stack Overflow
Here i need to use Pdf-Viewer in my app.i took many API as a reference but still stucking up in viewing Pdf files from SDCARD. here my code `First.java public class First extends ListActivity { S... More on stackoverflow.com
🌐 stackoverflow.com
Display PDF file inside my android application - Stack Overflow
I cannot figure out how to show a PDF file inside an Android application. So far I've found out that it is possible to launch an Intent and open the PDF using the Android default app. But I want to... More on stackoverflow.com
🌐 stackoverflow.com
How can I read and view PDF in android? - Stack Overflow
I am working on an application which require to open, read and view pdf in Android Application. I am having a pdf files in assets folder. By default android does not support pdf. Is there any API More on stackoverflow.com
🌐 stackoverflow.com
What's the Best Lightweight PDF App for Android?
Mjpdf - simple pdf reader no ads and just works https://play.google.com/store/apps/details?id=com.gitlab.mudlej.MjPdfReader More on reddit.com
🌐 r/androidapps
61
45
January 12, 2025
People also ask

More about PdfActivity

PdfActivity is a public class that extends AppCompatActivity(opens in a new tab) and implements [PdfUi], [PdfActivityListener], and PdfActivityComponentsApi. It’s an activity with fully integrated views and behavior, and it can be invoked by the simple helper methods [showDocument][showdocument]) and [showImage][showimage]).

🌐
nutrient.io
nutrient.io › blog › sdk › how to build an android pdf viewer
Build an Android PDF viewer using Nutrient: A step-by-step guide
What is an intent in Android?

Intents are messages you pass to the Android OS. They describe actions you want the system to perform on your behalf. After describing an intent, you pass it to the OS and act on the result. Usually, the result is passed to a callback function.

🌐
nutrient.io
nutrient.io › blog › sdk › how to build an android pdf viewer
Build an Android PDF viewer using Nutrient: A step-by-step guide
What’s a request code used for in Android?

In Android, request codes help identify intents and their corresponding results. The best place to declare a request code is in a separate file that holds all your constants.

🌐
nutrient.io
nutrient.io › blog › sdk › how to build an android pdf viewer
Build an Android PDF viewer using Nutrient: A step-by-step guide
🌐
Android Developers
developer.android.com › core areas › ui › views › android pdf viewer
Android PDF viewer | Views | Android Developers
June 11, 2026 - Learn about the Jetpack PDF viewer library and framework APIs to view and interact with PDF documents in your Android application.
🌐
Android Developers
developer.android.com › camera & media dev center › android pdf viewer
Android PDF viewer | Android media | Android Developers
The PDF viewer library (androidx.pdf), provides an embeddable PDF viewer UI that enables users to do the following: ... You can create a full-featured PDF experience by integrating the Jetpack library APIs or using the framework APIs directly.
🌐
Stack Overflow
stackoverflow.com › questions › 11499942 › android-code-to-implement-pdf-viewer
Android-Code to Implement PDF Viewer - Stack Overflow
Simply go to this Link "https://central.sonatype.com/artifact/com.github.mhiew/android-pdf-viewer/versions" and download .aar file from here and paste in libs folder. then add this in biuld.properties files "android.enableJetifier=true" after ...
Top answer
1 of 8
30

You can download the source from here(Display PDF file inside my android application)

Add this dependency in your gradle file:

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

activity_main.xml

<RelativeLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    xmlns:android="http://schemas.android.com/apk/res/android" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="@color/colorPrimaryDark"
        android:text="View PDF"
        android:textColor="#ffffff"
        android:id="@+id/tv_header"
        android:textSize="18dp"
        android:gravity="center"></TextView>

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


    </RelativeLayout>

MainActivity.java

package pdfviewer.pdfviewer;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import com.github.barteksc.pdfviewer.PDFView;
import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener;
import com.github.barteksc.pdfviewer.listener.OnPageChangeListener;
import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle;
import com.shockwave.pdfium.PdfDocument;

import java.util.List;

public class MainActivity extends Activity implements OnPageChangeListener,OnLoadCompleteListener{
    private static final String TAG = MainActivity.class.getSimpleName();
    public static final String SAMPLE_FILE = "android_tutorial.pdf";
    PDFView pdfView;
    Integer pageNumber = 0;
    String pdfFileName;

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


        pdfView= (PDFView)findViewById(R.id.pdfView);
        displayFromAsset(SAMPLE_FILE);
    }

    private void displayFromAsset(String assetFileName) {
        pdfFileName = assetFileName;

        pdfView.fromAsset(SAMPLE_FILE)
                .defaultPage(pageNumber)
                .enableSwipe(true)

                .swipeHorizontal(false)
                .onPageChange(this)
                .enableAnnotationRendering(true)
                .onLoad(this)
                .scrollHandle(new DefaultScrollHandle(this))
                .load();
    }


    @Override
    public void onPageChanged(int page, int pageCount) {
        pageNumber = page;
        setTitle(String.format("%s %s / %s", pdfFileName, page + 1, pageCount));
    }


    @Override
    public void loadComplete(int nbPages) {
        PdfDocument.Meta meta = pdfView.getDocumentMeta();
        printBookmarksTree(pdfView.getTableOfContents(), "-");

    }

    public void printBookmarksTree(List<PdfDocument.Bookmark> tree, String sep) {
        for (PdfDocument.Bookmark b : tree) {

            Log.e(TAG, String.format("%s %s, p %d", sep, b.getTitle(), b.getPageIdx()));

            if (b.hasChildren()) {
                printBookmarksTree(b.getChildren(), sep + "-");
            }
        }
    }

}
2 of 8
8

Maybe you can integrate MuPdf in your application. Here is I've described how to do this: Integrate MuPDF Reader in an app

Find elsewhere
🌐
Apryse
apryse.com › blog › build-an-android-pdf-viewer-using-java
How to Build an Android PDF Viewer Using Java | Apryse
November 21, 2018 - In this blog post, we’ll use PdfRenderer from the android.graphics.pdf package to create a basic PDF viewer in your Android app. Then, we'll see how easy it is to implement a document viewer using the Apryse SDK.
🌐
Nutrient
nutrient.io › blog › sdk › how to build an android pdf viewer
Build an Android PDF viewer using Nutrient: A step-by-step guide
1 month ago - This step-by-step guide demonstrates how to integrate Nutrient’s Android PDF SDK to build a feature-rich PDF viewer in Android applications. It covers project setup in Android Studio, adding the SDK dependency, displaying PDFs from assets and local storage, and accessing advanced features like annotations and form filling.
🌐
Medium
adiandrea.medium.com › pdfviewerfragment-androidx-library-for-viewing-pdf-419ef76bf43e
PDFViewerFragment - AndroidX Library for viewing PDF | by Adi Andrea | Medium
November 2, 2024 - This class required us to handle ... point is our APK size will not impacted. PDF Viewer Fragment is a new Androidx library designed to add PDF viewing capabilities inside our apps....
🌐
GitHub
github.com › DImuthuUpe › AndroidPdfViewer
GitHub - DImuthuUpe/AndroidPdfViewer: Android view for displaying PDFs rendered with PdfiumAndroid · GitHub
Android view for displaying PDFs rendered with PdfiumAndroid - DImuthuUpe/AndroidPdfViewer
Starred by 8.5K users
Forked by 2.1K users
Languages   Java
🌐
ComPDF
compdf.com › guides › pdf-sdk › android › viewer
Android PDF Viewer Library - PDF Viewer for Android
It offers developers a way to quickly embed a highly configurable PDF viewer in any Android application.
🌐
Medium
medium.com › @rjmittal07 › how-i-built-a-pdf-viewer-library-thats-both-lightweight-and-powerful-b238dc79d592
How I Built an Android PDF Viewer That's Lightweight and Powerful | Medium
April 24, 2025 - While this isn’t adaptive to screen size or zoom scale yet, the implementation is straightforward, effective, and easily configurable by library consumers. In the future, I plan to make this more intelligent — adjusting prefetch distance based on screen density, zoom level, or estimated scroll velocity — so that performance stays balanced across a wider range of devices and usage scenarios. 📁 PdfRendererCore → Rendering + Caching 📁 PdfDownloader → URL download w/ retry 📁 PdfViewAdapter → RecyclerView rendering 📁 PinchZoomRecyclerView → Zoom + pan logic
🌐
ComPDF
compdf.com › blog › build-an-android-pdf-viewer-or-editor-in-java
How to Build a Java Android PDF Viewer or Editor
More methods to add the package are given on the documentation page. The first thing we need to do is to import ComPDF SDK. Copy ComPDF.aar and ComPDF-UI.aar to the libs directory of the app.
🌐
Nutrient
nutrient.io › blog › sdk › open pdf android
How to view PDFs on Android - Nutrient
February 27, 2026 - Integration is simple. Start with adding a library dependency to your build.gradle file: compile 'com.github.barteksc:android-pdf-viewer:3.1.0-beta.1'
🌐
Blogger
devofandroid.blogspot.com › 2018 › 04 › pdf-reader-app-android-studio-tutorial.html
PDF reader app - Android Studio Tutorial
July 4, 2023 - A blog web site to learn the Android Application development from scratch to professional in Java and Kotlin using Android Studio. ... This tutorial is about: ✓Create PDF app. ✓Display Specific or all pages from PDF ✓Display PDF from Assets folder. ✓Add padding between pages ✓Passwords ✓Scroll PDF pages vertically or Swipe horizontally. implementation 'com.github.barteksc:android-pdf-viewer:3.0.0-beta.5'
🌐
GeeksforGeeks
geeksforgeeks.org › android › how-to-create-dynamic-pdf-viewer-in-android-with-firebase
How to Create Dynamic PDF Viewer in Android with Firebase? - GeeksforGeeks
Navigate to the app > Gradle Scripts > build.gradle file and make sure that the below dependency is added in your dependencies section. implementation 'com.google.firebase:firebase-database:19.6.0' After adding this dependency add the dependency ...
Published   July 23, 2025
🌐
Android Developers
developer.android.com › get started › jetpack › pdf
pdf | Jetpack | Android Developers
2 weeks ago - Exposes a new artifact pdf-document-service and the corresponding APIs - PdfLoader, PdfDocument and SandboxedPdfLoader. The interfaces can be used to implement the parsing and processing component of the PDF document (Ide70d)
🌐
Android Developers
developer.android.com › api reference › pdfrenderer
PdfRenderer | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
🌐
Pdf-Viewer
afreakyelf.github.io › Pdf-Viewer
Pdf-Viewer | A Lightweight PDF Viewer Android library which only occupies around 80kb while most of the Pdf viewer occupies up to 16MB space.
We have migrated our library to Maven Central for easier integration and better reliability. To use the Pdf Viewer library in your project, add the following dependency to your build.gradle file: dependencies { // Replace 'latest-version' with the actual latest version number implementation 'io.github.afreakyelf:Pdf-Viewer:latest-version' }