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
![](https://private-user-images.githubusercontent.com/74773876/268463457-be378d46-6a7f-4e87-bea8-61afa1fdcd75.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjUzMjU3NzMsIm5iZiI6MTcyNTMyNTQ3MywicGF0aCI6Ii83NDc3Mzg3Ni8yNjg0NjM0NTctYmUzNzhkNDYtNmE3Zi00ZTg3LWJlYTgtNjFhZmExZmRjZDc1LmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTAzVDAxMDQzM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTUwZDFiZGYzMzY5OGMxNTk4ZWVjZTNiOTQ1ZDRjZWVhNzFlYWE0NzE1NTA2NzBjNjc0ZDBlYjhlNmZhZDk3ZDgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.AZpMvq3KzsuzJVZZjF4sCCbzh4J3gASYxRNpRhL5SoE)
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'
}
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
}
}
}
}