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
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

🌐
YouTube
youtube.com › watch
Add PDF Files in Android Apps | PDF Viewer | Android Studio - YouTube
This is a tutorial about how to add or show pdf files in android apps. PDF View Library: https://github.com/barteksc/AndroidPdfViewerJoin our Facebook Group ...
Published   January 24, 2021
Discussions

How to open pdf file inside my app (android studio, JAVA) from firebase storage link - Stack Overflow
I have pdf file stored on my firebase ... my android app (android studio, JAVA). Not using INTENT , but directly inside my app. ... You can use android-pdfView, see this blog post. It demonstrates the basic usage of the library to display pdf onto the view with vertical and horizontal ... More on stackoverflow.com
🌐 stackoverflow.com
Good PDF Library ?
Have you considered the default PdfRenderer? https://developer.android.com/reference/android/graphics/pdf/PdfRenderer More on reddit.com
🌐 r/androiddev
15
4
February 27, 2022
Managing files in the "Android/data" folder on Android 11 (without root or USB)

Once again the iron grip of Google on AOSP, so many AOSP apps are frozen in favor of Google apps.

More on reddit.com
🌐 r/Android
111
237
October 2, 2020
How to change the color of a date in calendar view?
Also i noticed that most of the methods to do what i want have been depreciated for some reason. Like half the calendar view methods are now depreciated.... wow. More on reddit.com
🌐 r/androiddev
2
3
March 8, 2016
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
🌐
Medium
medium.com › @andiaspin › how-to-open-pdf-in-android-studio-f31b1fd2d011
How To Open Pdf in Android Studio | by Andi Asvin Mahersatillah Suradi | Medium
April 3, 2020 - As usual, create a new project. then add the Assets folder Right-click the project > New > Folder > Folder Assets · Press enter or click to view image in full size · Then, in the Assets folder you save your PDF file ·
🌐
Medium
medium.com › @generalfocus1 › build-your-own-android-pdf-reader-from-scratch-using-android-studio-ac65601eb90
Build Android PDF Reader From Scratch Using Android Studio | by Oyinkansola Olabode | Medium
April 6, 2020 - But this tutorial will focus majorly ... build an inbuilt pdf reader. I will assume the reader of this tutorial has basic android development skill which will make me skip some part such as new project creation on android studio; activity selection and other fundamentals of creating an android studio project. After creating your android studio project, add the dependency below to your gradle file · implementation 'com.github.barteksc:android-pdf-viewer:3.0.0-...
🌐
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.
🌐
GitHub
github.com › DImuthuUpe › AndroidPdfViewer
GitHub - DImuthuUpe/AndroidPdfViewer: Android view for displaying PDFs rendered with PdfiumAndroid · GitHub
It is based on PdfiumAndroid for decoding PDF files. Works on API 11 (Android 3.0) and higher. Licensed under Apache License 2.0. ... Removed page size parameters from OnRenderListener#onInitiallyRendered(int) method, as document may have different page sizes
Starred by 8.5K users
Forked by 2.1K users
Languages   Java
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-load-pdf-from-url-in-android
How to Load PDF from URL in Android? - GeeksforGeeks
April 1, 2025 - <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <!--PDF Viewer to display our PDF--> <com.github.barteksc.pdfviewer.PDFView android:id="@+id/pdfView" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout>
🌐
YouTube
youtube.com › watch
PdfViewer App - Load Local Pdfs From Device ( Android Studio ) - YouTube
In This Video, I am gonna show you how to create pdf viewer app with library . Load local pdfs from device to our app.Connect with us -Follow me on Instagram...
Published   June 10, 2023
🌐
Blogger
devofandroid.blogspot.com › 2018 › 04 › pdf-reader-app-android-studio-tutorial.html
PDF reader app - Android Studio Tutorial
July 4, 2023 - package com.blogspot.devofandroid.pdfapp; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import com.github.barteksc.pdfviewer.PDFView; import com.github.barteksc.pdfviewer.util.FitPolicy; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //PDF View PDFView pdfView = findViewById(R.id.pdfView); pdfView.fromAsset("pdfexample.pdf") .enableSwipe(true) // allows to block changing pages using swipe .swipeHorizontal(true) .enableDou
🌐
Android Developers
developer.android.com › api reference › pdfrenderer
PdfRenderer | API reference | Android Developers
Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体 · 日本語 · 한국어 Android Studio ·
🌐
YouTube
youtube.com › solution code android
PDF View Show in android studio kotlin #solutioncodeandroid /load pdf view in android studio - YouTube
PDF View Show in android studio kotlinhow to show PDF in android studio kotlin #solutioncodeandroid /load pdf view in android studio PDF view tutorialIn this...
Published   March 4, 2024
Views   664
🌐
DEV Community
dev.to › ahsanahmed03 › retrieving-and-displaying-pdf-files-in-android-studio-using-java-step-by-step-guide-1nlm
Retrieving and Displaying PDF Files in Android Studio using Java: Step-by-Step Guide - DEV Community
November 30, 2024 - You'll learn how to handle item clicks in the RecyclerView and launch the appropriate viewer app with the selected PDF file. Step 5: Testing and Refining the App Once the retrieval and display functionalities are implemented, we'll guide you through testing your app on an emulator or a physical Android device.
🌐
PSPDFKit
pspdfkit.com › blog › sdk › open pdf android
How to view PDFs on Android
February 27, 2026 - Your browser doesn't support HTML5 video. Here is a link to the video instead. To integrate Nutrient into your Android app, follow the steps outlined below. Open Android Studio and select File > New > New Project….
🌐
Android Developers
developer.android.com › camera & media dev center › android pdf viewer
Android PDF viewer | Android media | Android Developers
한국어 Android Studio · Sign in · Camera & media dev center · Android Developers · Essentials · Camera & media dev center · Guides · The Jetpack PDF viewer library, backed by framework APIs, offers a ready-made, performant solution ...
🌐
Stack Overflow
stackoverflow.com › questions › 66774763 › how-to-open-pdf-file-inside-my-app-android-studio-java-from-firebase-storage
How to open pdf file inside my app (android studio, JAVA) from firebase storage link - Stack Overflow
<com.github.barteksc.pdfviewer.PDFView android:visibility="visible" android:id="@+id/pdfView" android:layout_width="match_parent" android:layout_height="match_parent"/> ... { String pdfurl="firebase_access_token_of_pdf_file"; pdfView = (PDFView) findViewById(R.id.pdfView); new RetrivePDFfromUrl().execute(pdfUrl); } // create an async task class for loading pdf file from URL. class RetrivePDFfromUrl extends AsyncTask<String, Void, InputStream> { @Override protected InputStream doInBackground(String...
🌐
Quora
quora.com › How-can-I-develop-a-PDF-viewer-app-using-Android-Studio
How to develop a PDF viewer app using Android Studio - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
🌐
Reintech
reintech.io › blog › implementing-pdf-reader-app-android-using-pdfrenderer
Implementing a PDF reader app for Android using PDFRenderer | Reintech media
February 3, 2026 - The android-pdf-viewer library is particularly useful when you need a production-ready PDF viewer without implementing low-level rendering logic. For applications requiring fine-grained control over rendering or custom UI interactions, the native PdfRenderer may be more appropriate. Create a new Android project in Android Studio with the "Empty Activity" template.
🌐
ComPDF
compdf.com › blog › build-an-android-pdf-viewer-or-editor-in-java
How to Build a Java Android PDF Viewer or Editor
ComPDF also provides the guides to build an Android PDF Editor. 1. Copy a PDF document into the assets directory of your Android project. For example, import the file Quick Start Guide.pdf to the path src/main/assets.
🌐
Android Developers
developer.android.com › camera & media dev center › implement a pdf viewer
Implement a PDF viewer | Android media | Android Developers
November 17, 2025 - Begin by defining the layout XML for the activity that hosts the PDF viewer. The layout should include a FrameLayout to contain the PdfViewerFragment and buttons for user interactions, such as searching within the document.
🌐
YouTube
youtube.com › pavi_techzone
PDF Viewer :How to Open PDF File in Android #androidstudio #pdfview - YouTube
Android PdfViewer: https://github.com/barteksc/AndroidPdfViewer👍Subscribe to the Channelhttps://youtube.com/@Pavi_TechZone?si=0vivJvQfo-teaor7#androidstudio...
Published   February 16, 2024
Views   295