Pdf Renderer API Android From URL

I am learning the PDF rendering API native to Google Android development. I see the following code example in the documentation:

 // 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 is used from File Object. How can I get this API to work with a url from a web server like a document from a website? How do I download a PDF natively to an Android app that doesn't require uploading the file to local storage? Something like how you can start the google doc viewer to open the pdf in web browse, but i can't take this approach because google doc viewer is locked in the environment i am in.

+3


source to share


2 answers


how can i get this API to work with url from 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 to download the pdf file in an android app, not requiring the file to be downloaded to local storage

AFAIK, you cannot use PdfRenderer

this way. It needs a search engine to do this FileDescriptor

, and the only way I know to create one of these is with a local file.

0


source


You cannot use Pdf Renderer to load url. But you can use Google Docs in your web browser to download the url without downloading the file ...



webView.loadUrl("https://docs.google.com/gview?embedded=true&url=" + YOUR_URL);

      

0


source







All Articles