How to create pdf in view pager Android?

Source link:

Here an example how to create pdf in view pager.


Download Android Arsenal Build Status

Android widget to display PDF documents in your Activities or Fragments.

Important note: PDFViewPager uses PdfRenderer class, which works only on API 21 or higher. See Official doc for details.

If you are targeting pre-Lollipop devices, have a look at the legacy sample


Add this line in your app/build.gradle

implementation  es.voghdev.pdfviewpager:library:1.1.2  

If you want to use the old instead of androidx, add this dependency

implementation  es.voghdev.pdfviewpager:library:1.0.6  


Use PDFViewPager class to load PDF files from assets or SD card

Screenshot Screenshot

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)

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() {


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

  protected void onDestroy() {


 ((PDFPagerAdapter) pdfViewPager.getAdapter()).close();


Remote PDF s from a URL


1.- Add INTERNET, READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions on your AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 

2.- Make your Activity or Fragment implement DownloadFile.Listener

public class RemotePDFActivity extends AppCompatActivity implements DownloadFile.Listener {

3.- Create a RemotePDFViewPager object

String url = "";  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 fine

adapter = new PDFPagerAdapter(this, "AdobeXMLFormsSamples.pdf");


  @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() {



Usage in Kotlin

As you might figure out, the library is fully usable in Kotlin programming language. You can find example code here.

Just import the library as a gradle dependency as you would do in Java.


  • Make initial Pdf scale setable by code (requested by various users on issues)
  • Load PDF documents from SD card
  • Make PDF documents zoomable with pinch and double tap (two approaches, ImageViewZoom and photoview)
  • Unify all features in only one PDFViewPager and PDFPagerAdapter class
  • Support API Levels under 21, by downloading PDF and invoking system native intent.
  • UI tests
  • Add checkstyle, refactor & improve code quality

See changelog for details

Developed By

Follow me on Twitter Find me on Linkedin


This repository has been supported by JetBrains with free licenses for all JetBrains products


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


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 


Android library to create complex multi-state animations.

A library for simple communication with Google Cloud Storage.


  • Simple CRUD (Create, Read, Update and Delete) functions for Bitmaps.
  • Simple Builder pattern for credentials and bucket storage.
  • Custom or standard JSON factory and HTTP transporter.
  • Easy to debug with existing, simple to understand debug log.

This is a super simple plugin to be used in combination with the new unit testing feature of the Gradle Plugin / Android Studio.

It tries to solve the problem that you have to mock each and every Android SDK class (even SparseArray, TextUtils etc.) by allowing you to use selected classes from a real Android-Jarfile.

NiceSpinner is a re-implementation of the default Android's spinner, with a nice arrow animation and a different way to display its content.

PrismView provides animations for your views, similar to Dragger, but with fragments! You can change the fragment of the PrismView any time and it works like a ViewPager.

Android custom view and progress for music player.


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes