Explore Courses Blog Tutorials Interview Questions
0 votes
in Java by (3.4k points)

I realized that Android has no built-in method of displaying PDF files.

How can I render a PDF file using Java on Android?

1 Answer

0 votes
by (46k points)

Since API Level 21 (Lollipop) Android provides a PdfRenderer class:

// Make a new renderer

 PdfRenderer renderer = new PdfRenderer(getSeekableFileDescriptor());

 // let us just render all pages

 final int pageCount = renderer.getPageCount();

 for (int i = 0; i < pageCount; i++) {

     Page page = renderer.openPage(i);

     // say we render for showing on the screen

     page.render(mBitmap, null, null, Page.RENDER_MODE_FOR_DISPLAY);

     // do stuff with the bitmap

     // close the page



 // close the renderer


For added erudition check the sample app.

For older APIs I promote Android PdfViewer library, it is pretty fast and easy to apply, authorized under Apache License 2.0:


  .pages(0, 2, 1, 3, 3, 3) // all pages are displayed by default














Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jan 2, 2021 in Python by laddulakshana (16.4k points)

Browse Categories