Skip to content

Android library which provides a lightweight PDF viewer for local PDF files

Notifications You must be signed in to change notification settings

rishujam/PdfViewer

Repository files navigation

Local PDF Viewer Library for Android

Overview

This Android library provides a lightweight and easy-to-use PDF viewer for local and online PDF files within your Android applications. Whether you want to include a PDF viewer in your app for reading documents or displaying user manuals, this library simplifies the integration process.

Key features:

  • View local PDF files.
  • View online PDF files.
  • Smooth and intuitive user interface.
  • Pinch to zoom

Screenshot

Installation

settings.gradle:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

To get started, add the library to your Android project by including it as a dependency. You can do this by adding the following lines to your app's build.gradle file:

gradle

dependencies {
    implementation 'com.github.rishujam:PdfViewer:1.5'
}

How to use

XML File

    <com.docs.docwatcher.DocView
		android:id="@+id/docView"
		android:layout_width="match_parent"
		android:layout_height="match_parent"/>

Fragment/Activity

    companion object {
        private const val PATH = "/data/data/com.docs.pdfviewer/files/sample_pdf.pdf"
	private const val INTERNET_PATH =
            "https://research.nhm.org/pdfs/10840/10840-001.pdf"
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

	//If the path specified is a url you must set fromInternet value to true else set it to false.

        binding.docView.loadData(
            uri = INTERNET_PATH, 
            fromInternet = true,
        ) 

	// If you are loading pdf from url you can easily track progress using this function

	binding.docView.setDownloadStateChangeListener {
            when (it) {
                is DownloadState.Error -> {
                    Toast.makeText(this, it.message, Toast.LENGTH_SHORT).show()
                }

                is DownloadState.Completed -> {
                    //Do something..
                }

                is DownloadState.InProgress -> {
                    val totalFileSizeInBytes = it.totalSize
                    val progress = it.progress
                }
            }
        }
    }

About

Android library which provides a lightweight PDF viewer for local PDF files

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages