Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/voghDev/PdfViewPager
Android widget that can render PDF documents stored on SD card, linked as assets, or downloaded from a remote URL.
https://github.com/voghDev/PdfViewPager
android espresso library pdf pdf-book pdf-document rendering testing ui ui-automated-tests
Last synced: 2 months ago
JSON representation
Android widget that can render PDF documents stored on SD card, linked as assets, or downloaded from a remote URL.
- Host: GitHub
- URL: https://github.com/voghDev/PdfViewPager
- Owner: voghDev
- License: apache-2.0
- Created: 2016-02-10T17:30:23.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-09-14T17:00:12.000Z (over 3 years ago)
- Last Synced: 2024-10-31T02:08:08.550Z (2 months ago)
- Topics: android, espresso, library, pdf, pdf-book, pdf-document, rendering, testing, ui, ui-automated-tests
- Language: Java
- Size: 14.8 MB
- Stars: 1,695
- Watchers: 64
- Forks: 331
- Open Issues: 45
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-pdf - PdfViewPager
- awesome-pdf - PdfViewPager
- awesome-list - voghDev/PdfViewPager - Android widget that can render PDF documents stored on SD card, linked as assets, or downloaded from a remote URL. (Java)
- awesome-github-android-ui - PdfViewPager - 在Activities或Fragments中显示PDF文档 (ViewPager)
README
# PdfViewPager
[![Download](https://api.bintray.com/packages/voghdev/maven/pdfviewpager/images/download.svg) ](https://bintray.com/voghdev/maven/pdfviewpager/_latestVersion)
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-PdfViewPager-green.svg?style=true)](https://android-arsenal.com/details/1/3155)
[![Build Status](https://travis-ci.org/voghDev/PdfViewPager.svg?branch=master)](https://travis-ci.org/voghDev/PdfViewPager)Android widget to display PDF documents in your Activities or Fragments.
Important note: **PDFViewPager** uses [PdfRenderer][6] class, which works **only on API 21 or higher**.
See [Official doc][6] for details.If you are targeting pre-Lollipop devices, have a look at the [legacy sample][7]
Installation
------------Add this line in your *app/build.gradle*
implementation 'es.voghdev.pdfviewpager:library:1.1.2'
If you want to use the old `android.support` instead of `androidx`, add this dependency
implementation 'es.voghdev.pdfviewpager:library:1.0.6'
Usage
-----Use **PDFViewPager** class to load PDF files from assets or SD card
![Screenshot][localPDFScreenshot] ![Screenshot][zoomingScreenshot]
1.- Copy your assets to cache directory if your PDF is located on assets directory
CopyAsset copyAsset = new CopyAssetThreadImpl(context, new Handler());
copyAsset.copy(asset, new File(getCacheDir(), "sample.pdf").getAbsolutePath());2a.- Create your **PDFViewPager** passing your PDF file, located in *assets* (see [sample][8])
pdfViewPager = new PDFViewPager(this, "sample.pdf");
2b.- Or directly, declare it on your XML layout
It will automatically have zooming and panning capability
3.- Release adapter in *onDestroy*
@Override
protected void onDestroy() {
super.onDestroy();((PDFPagerAdapter) pdfViewPager.getAdapter()).close();
}PDF's on SD card
----------------1.- Create a **PDFViewPager** object, passing the file location in your SD card
PDFViewPager pdfViewPager = new PDFViewPager(context, getPdfPathOnSDCard());
protected String getPdfPathOnSDCard() {
File f = new File(getExternalFilesDir("pdf"), "adobe.pdf");
return f.getAbsolutePath();
}2.- Don't forget to release the adapter in *onDestroy*
@Override
protected void onDestroy() {
super.onDestroy();((PDFPagerAdapter) pdfViewPager.getAdapter()).close();
}Remote PDF's from a URL
-----------------------![Screenshot][remotePDFScreenshot]
1.- Add `INTERNET`, `READ_EXTERNAL_STORAGE` and `WRITE_EXTERNAL_STORAGE` permissions on your AndroidManifest.xml
2.- Make your Activity or Fragment implement DownloadFile.Listener
public class RemotePDFActivity extends AppCompatActivity implements DownloadFile.Listener {
3.- Create a **RemotePDFViewPager** object
String url = "http://www.cals.uidaho.edu/edComm/curricula/CustRel_curriculum/content/sample.pdf";
RemotePDFViewPager remotePDFViewPager =
new RemotePDFViewPager(context, url, this);4.- Configure the corresponding callbacks and they will be called on each situation.
@Override
public void onSuccess(String url, String destinationPath) {
// That's the positive case. PDF Download went fineadapter = new PDFPagerAdapter(this, "AdobeXMLFormsSamples.pdf");
remotePDFViewPager.setAdapter(adapter);
setContentView(remotePDFViewPager);
}@Override
public void onFailure(Exception e) {
// This will be called if download fails
}@Override
public void onProgressUpdate(int progress, int total) {
// You will get download progress here
// Always on UI Thread so feel free to update your views here
}5.- Don't forget to close adapter in *onDestroy* to release all resources
@Override
protected void onDestroy() {
super.onDestroy();adapter.close();
}Usage in Kotlin
---------------As you might figure out, the library is fully usable in Kotlin programming language. You can find example code [here][12].
Just import the library as a gradle dependency as you would do in Java.
TODOs
------ [X] Make initial Pdf scale setable by code *(requested by various users on issues)*
- [X] Load PDF documents from SD card
- [X] Make PDF documents zoomable with pinch and double tap (two approaches, [ImageViewZoom][5] and [photoview][11])
- [X] Unify all features in only one **PDFViewPager** and **PDFPagerAdapter** class
- [X] Support API Levels under 21, by downloading PDF and invoking system native intent.
- [X] UI tests
- [X] Add checkstyle, refactor & improve code qualitySee [changelog][4] for details
Developed By
------------* Olmo Gallegos Hernández - [voghDev][9] - [mobiledevstories.com][10]
Support
-------This repository has been supported by JetBrains with free licenses for all JetBrains products
# License
Copyright 2016 Olmo Gallegos Hernández
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.Contributing
------------**For noobs (like me some months ago)**
fork the project into your GitHub account
now clone your GitHub repo for this project
implement your changes
commit your changes, push them into your repo
review your code and send me a pull request if you consider it**For not-so-noobs**
Please make sure that your changes pass both checkstyle and UI tests before submitting them
./gradlew checkstyle
./gradlew test
And with your Android device connected
./gradlew connectedCheck
[remotePDFScreenshot]: ./screenshots/remote.gif
[localPDFScreenshot]: ./screenshots/local.gif
[sdcardPDFScreenshot]: ./screenshots/sdcard.gif
[zoomingScreenshot]: ./screenshots/zooming.gif
[4]: https://github.com/voghDev/PdfViewPager/blob/master/CHANGELOG.md
[5]: https://github.com/sephiroth74/ImageViewZoom
[6]: http://developer.android.com/reference/android/graphics/pdf/PdfRenderer.html
[7]: https://github.com/voghDev/PdfViewPager/blob/27b61836168a09fec9287726246bd7b3da8aae74/sample/src/main/java/es/voghdev/pdfviewpager/LegacyPDFActivity.java
[8]: https://github.com/voghDev/PdfViewPager/tree/master/sample/src/main/java/es/voghdev/pdfviewpager
[9]: https://github.com/voghDev
[10]: http://www.mobiledevstories.com
[11]: https://github.com/chrisbanes/PhotoView
[12]: https://github.com/voghDev/HelloKotlin/blob/pdfviewpager/app/src/main/java/es/voghdev/hellokotlin/PdfViewPagerActivity.kt