I am unable to read PDF file from assets folder. how could i read a PDF in a single page with integrating all controls available for a PDF viewer. I don't want to open a default pdf viewer available in the phone. Please suggest me the right way to achieve interactive PDF viewer with in the android application which can read the pdf from assets/raw folder from the android resource components. Thanks in advance
2 Answers
You can use Intent
to load your PDF in external application.
File file = //Load your file from assets here
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
You can load file from assets using InputStream
. See this post.
Good luck!

- 1
- 1

- 2,694
- 23
- 38
-
Really are you calling this integration of a PDF READER? Thanks – Ivor Feb 26 '16 at 15:50
It helped for me:
Barteksc Android Pdf SDK Library
Android PdfViewer AndroidPdfViewer 1.x is available on the AndroidPdfViewerV1 repo, where can be developed independently. Version 1.x uses a different engine for drawing documents on canvas, so if you don't like the 2.x version, try 1.x.
Library for displaying PDF documents on Android, with animations, gestures, zoom, and double-tap support. It is based on PdfiumAndroid for decoding PDF files. Works on API 11 (Android 3.0) and higher. Licensed under Apache License 2.0.
Which supports Android devices from Android 4.4.4 (KitKat)
Installation
Add to build.gradle:
implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'
or if you want to use more stable version:
implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
Add this into your layout file:
<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/your_pdf_id"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
You can Load a PDF file like this:
pdfView.fromUri(Uri)
or
pdfView.fromFile(File)
or
pdfView.fromBytes(byte[])
or
pdfView.fromStream(InputStream) // stream is written to bytearray - native code cannot use Java Streams
or
pdfView.fromSource(DocumentSource)
or
pdfView.fromAsset(String)
.pages(0, 2, 1, 3, 3, 3) // all pages are displayed by default
.enableSwipe(true) // allows to block changing pages using swipe
.swipeHorizontal(false)
.enableDoubletap(true)
.defaultPage(0)
// allows to draw something on the current page, usually visible in the middle of the screen
.onDraw(onDrawListener)
// allows to draw something on all pages, separately for every page. Called only for visible pages
.onDrawAll(onDrawListener)
.onLoad(onLoadCompleteListener) // called after document is loaded and starts to be rendered
.onPageChange(onPageChangeListener)
.onPageScroll(onPageScrollListener)
.onError(onErrorListener)
.onPageError(onPageErrorListener)
.onRender(onRenderListener) // called after document is rendered for the first time
// called on single tap, return true if handled, false to toggle scroll handle visibility
.onTap(onTapListener)
.onLongPress(onLongPressListener)
.enableAnnotationRendering(false) // render annotations (such as comments, colors or forms)
.password(null)
.scrollHandle(null)
.enableAntialiasing(true) // improve rendering a little bit on low-res screens
// spacing between pages in dp. To define spacing color, set view background
.spacing(0)
.autoSpacing(false) // add dynamic spacing to fit each page on its own on the screen
.linkHandler(DefaultLinkHandler)
.pageFitPolicy(FitPolicy.WIDTH) // mode to fit pages in the view
.fitEachPage(false) // fit each page to the view, else smaller pages are scaled relative to largest page.
.pageSnap(false) // snap pages to screen boundaries
.pageFling(false) // make a fling change only a single page like ViewPager
.nightMode(false) // toggle night mode
.load();
For More Information Github: Barteksc Android Pdf Viewer
I Hope, it Helps!

- 310
- 6
- 17