1

The core part of my application is load PDF online and user have access to download it as per their given rights.

The problem I am facing is that I want to load pdf online. After many research I have found that,

There are likely two ways to show pdf online in android:

1) In Web view by loading simple hosted URL

2) By google doc.

But in our case, if we use way (1), the mobile web view does not redirect hosted url of PDF. And if we use way (2), then there are certain limitations of the google docs regarding the file sizes. (Small pdf it will load like 5 to 10 with size of 1MB)

But after loading PDF with the size of 2 or 3 MB it's also giving me error as "No PREVIEW AVAILABLE" and its continuously giving me this error opening different urls.

So it seems there is still no easy solution for viewing a pdf from url (online without downloading pdf).

The other way to open pdf online is that we can open it in any other third party applications like browser, adobe pdf reader or any kind of pdf viewer application available in the device.

Cons: If we open pdf in browser then it will get downloaded automatically and if we open it in any third party application then they have options to download the pdf.

Please give me some solution to read the PDF online.

And if there are any paid pdf SDK availble which gives functionality of loading pdf online from URL, then please provide information of that too.

Please also suggest me some pdf viewer library for displaying pdf online.

I have used many of the library, but it increases my application's size to 8 to 10 MB.

Thanks in advance.

KishuDroid
  • 5,411
  • 4
  • 30
  • 47

2 Answers2

1

The suggested primary solution,

Download the file, store it in the app specific folder so users don't have access. For viewers who don't have access rights to download it, you will delete the file as they leave the view. For viewers who have access rights to download it, they will be given an option to copy the file to their SD card (an accessible location) and then you will delete the original file as they leave the view.

For storing in app specific directory to restrict user access,

http://www.grokkingandroid.com/how-to-correctly-store-app-specific-files-in-android/

Also use a library to view the pdf(MUCH SIMPLER), choose an appropriate one from here https://android-arsenal.com/search?q=pdf

Alternate solution,

If security is a major concern, you can encrypt the pdf file and store it on the server. And decrypt the file when you download it to the device.

For added security, don't store the file as pdf, just store it as a file. Download it as a file. Set type as pdf when you want to access it.

Conclusion,

Data wise, Even if you load it online, the device will consume almost same data as downloading the pdf. (Infact for viewing something online, your device downloads the data and stores it in the cache and you can view it)

Security wise, only a rooted phone will be able to access the file but that too for as long as you have decided to store it.

  • Thank you for the solution. I have already applied the first solution, but also appreciated your alternative solution and would like to apply it once. – KishuDroid Dec 23 '16 at 12:21
0

I suggest you check out PDF.js, a Javascript library from Mozilla to render PDF's in a browser. You can adapt this into a WebView easily, and display PDF's without downloading them.

Here is an open source app which does something similar to what you're looking for

Faraz
  • 643
  • 4
  • 15