Java – PDF Renderer API Android comes from URLs

PDF Renderer API Android comes from URLs… here is a solution to the problem.

PDF Renderer API Android comes from URLs

I’m investigating the PDF renderer API Native to Google Android development. I see the following code example in the docs:

 // create 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
 page.close();
 }

 close the renderer
 renderer.close();

I think this example uses a file object. How do I get this API to work with URLs from a web server, such as documents from a website? How do I load PDFs locally to local storage in Android apps that don’t require downloading files? Similar to how to run Google Documents Viewer to open a PDF in Web View – but I can’t do this because Google Docs Viewer is blocked in my environment.

Solution

how I can get this API to work with URL from a webserver?

Download the PDF from the server to a local file. Then, use a local file.

The purpose of what I am trying to learn is how to load pdf natively in android app that does not require a download of the file onto the local storage

AFAIK, you can’t use PdfRenderer like that. It requires a searchable FileDescriptor, and as far as I know, the only way to create one of these files involves a local file.

Related Problems and Solutions