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
how to read pdf file file in android studio - Stack Overflow
I'm a beginner in android development , I want to make android app that can read pdf files. the pdf files that i have is with large contests (each pdf file around 60 mb) , as i searched i need to store the files in the server like website or something ( i don't know exactly is that what i need ) if i will store the files on server how can i make the users read the pdf files without downloading them into their phones? . i found that i need to use web view ... 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
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
4 weeks 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.
🌐
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>
Find elsewhere
🌐
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
🌐
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
🌐
Android Developers
developer.android.com › api reference › pdfrenderer
PdfRenderer | API reference | Android Developers
Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体 · 日本語 · 한국어 Android Studio ·
🌐
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
🌐
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 ...
🌐
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.
🌐
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...
🌐
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.
🌐
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.
🌐
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.
Top answer
1 of 1
2

You can view a pdf file in an android project in different ways. I will describe some of them here-

1. Using Library: Steps are below:

Installation Add to build.gradle: implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
ProGuard If you are using ProGuard, add following rule to proguard config file:
-keep class com.shockwave.**
Include PDFView in your layout
<com.github.barteksc.pdfviewer.PDFView android:id="@+id/pdfView" android:layout_width="match_parent" android:layout_height="match_parent"/>
Further link is here
2. Load pdf url into webview:

webview = (WebView)findViewById(R.id.webview);
    progressbar = (ProgressBar) findViewById(R.id.progressbar);
    webview.getSettings().setJavaScriptEnabled(true);
    String filename = file_url_with_name;
    webview.loadUrl(file_url + filename);

    webview.setWebViewClient(new WebViewClient() {

        public void onPageFinished(WebView view, String url) {
            // do your stuff here
            progressbar.setVisibility(View.GONE);
        }
    });


3. Manually show PDF file into Imageview

// Example for creating manual PDF viewer into imageview used butterknife view binding<br/>

public class PdfRenderActivity extends AppCompatActivity {

    @BindView(R.id.pdf_image) ImageView imageViewPdf;
    @BindView(R.id.button_pre_doc) FloatingActionButton prePageButton;
    @BindView(R.id.button_next_doc) FloatingActionButton nextPageButton;

    private static final String FILENAME = "report.pdf";

    private int pageIndex;
    private PdfRenderer pdfRenderer;
    private PdfRenderer.Page currentPage;
    private ParcelFileDescriptor parcelFileDescriptor;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pdf_render);
        ButterKnife.bind(this);
        pageIndex = 0;
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onStart() {
        super.onStart();
        try {
            openRenderer(getApplicationContext());
            showPage(pageIndex);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    public void onStop() {
        try {
            closeRenderer();
        } catch (IOException e) {
            e.printStackTrace();
        }
        super.onStop();
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @OnClick(R.id.button_pre_doc)
    public void onPreviousDocClick(){
        showPage(currentPage.getIndex() - 1);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @OnClick(R.id.button_next_doc)
    public void onNextDocClick(){
        showPage(currentPage.getIndex() + 1);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    private void openRenderer(Context context) throws IOException {
        // In this sample, we read a PDF from the assets directory.
        File file = new File(context.getCacheDir(), FILENAME);
        if (!file.exists()) {
            // Since PdfRenderer cannot handle the compressed asset file directly, we copy it into
            // the cache directory.
            InputStream asset = context.getAssets().open(FILENAME);
            FileOutputStream output = new FileOutputStream(file);
            final byte[] buffer = new byte[1024];
            int size;
            while ((size = asset.read(buffer)) != -1) {
                output.write(buffer, 0, size);
            }
            asset.close();
            output.close();
        }
        parcelFileDescriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
        // This is the PdfRenderer we use to render the PDF.
        if (parcelFileDescriptor != null) {
            pdfRenderer = new PdfRenderer(parcelFileDescriptor);
        }
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    private void closeRenderer() throws IOException {
        if (null != currentPage) {
            currentPage.close();
        }
        pdfRenderer.close();
        parcelFileDescriptor.close();
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    private void showPage(int index) {
        if (pdfRenderer.getPageCount() <= index) {
            return;
        }
        // Make sure to close the current page before opening another one.
        if (null != currentPage) {
            currentPage.close();
        }
        // Use `openPage` to open a specific page in PDF.
        currentPage = pdfRenderer.openPage(index);
        // Important: the destination bitmap must be ARGB (not RGB).
        Bitmap bitmap = Bitmap.createBitmap(currentPage.getWidth(), currentPage.getHeight(),
                Bitmap.Config.ARGB_8888);
        // Here, we render the page onto the Bitmap.
        // To render a portion of the page, use the second and third parameter. Pass nulls to get
        // the default result.
        // Pass either RENDER_MODE_FOR_DISPLAY or RENDER_MODE_FOR_PRINT for the last parameter.
        currentPage.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
        // We are ready to show the Bitmap to user.
        imageViewPdf.setImageBitmap(bitmap);
        updateUi();
    }

    /**
     * Updates the state of 2 control buttons in response to the current page index.
     */
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    private void updateUi() {
        int index = currentPage.getIndex();
        int pageCount = pdfRenderer.getPageCount();
        prePageButton.setEnabled(0 != index);
        nextPageButton.setEnabled(index + 1 < pageCount);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public int getPageCount() {
        return pdfRenderer.getPageCount();
    }

}

Doc is here