I am trying to display a PDF in an Android application.
Constraints are: PDF cannot be downloaded to the mobile phone. Server through which PDF is getting downloaded is on Local network.
I can work on any option: getting the PDF to display on webview (more preferable) or getting the PDF to display using native technique.
Also if any solution involves converting the PDF to HTML and then displaying it will also be acceptable.
you can use third party library for this
https://github.com/voghDev/PdfViewPager
it works for me
Related
I am currently using 2.8.2 version of AndroidPdfViewer were it only displays pdf from internet links (with .pdf extension url) , I want to display my own pdf how can I do so, currently using Android Studio, language Kotlin
I was following this geeksforgeeks article and was able to fetch and display pdfs from internet which are already available but i want my own pdf to display and I don't have my own website.
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.
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.
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
I'm looking for a way to display a pdf that is loaded in a webview.
The case is as follows:
- We load a (external) web application inside a webview.
- The web application is secured, users have to login to access their data.
- When the user has logged in there is a button for downloading a pdf file.
- On iOS the pdf file is being displayed inside the webview, on Android it isn't.
- It is not possible to access the pdf by using a webservice instead of the webview (so, Titanium.Network.HTTPClient cannot be used)
We tried several solutions that we found on the internet. Unfortunately, till now without any success.
We tried:
- Google's documentviewer: http://docs.google.com/viewer?embedded=true&url=. This is not working because the pdf is 'behind' a username/password. Google is not aware of the session.
- Saving the pdf to the local file system and open it with Android Intent. We did not succeed in saving the pdf on the local filesystem.
The last option (saving the pdf and open it by using Ti.Android.Intent) seems to be the best option. But is it possible to save a pdf from a webview???
Maybe an external module (or using pdf.js) is also an option.
Can someone point me in the right direction.
We even don't know if what we want is possible?
Any help is really appreciated.
Stefan.
I have a PhoneGap app for Android which I am trying to run in the Android emulator. The app has a simple html page which has a button. On click, the button calls a RESTful webservice using javascript XMLHttpRequest and the service returns back base 64 encoded data for a pdf. Then from the javascript function, I try to load the pdf data in my html page in the app as below
document.location.href = 'data:application/pdf;base64,' + pdfData.childNodes[0].data;
But this does nothing. The data is returned correctly and I checked the logs for it. But the pdf is not displayed at all. Any idea what is causing the issue?
In Android you not show pdf file in Webview. Have some solution to view pdf file in Android:
Use google pdf view
mWebView.loadUrl("https://docs.google.com/gview?embedded=true&url="+LinkTo_pdfFile);
Download pdf file and view by pdf reader in device. Check this
(My solution) I parse pdf file to image and store onto server and i only download and view image directly.(It have bit complex, but you can view pdf, docx, xls,..). Example here
I am downloading PDF file in my application and want to allow user to view it. Is it possible that using webview I can display that pdf file downloaded to SD Card or local memory.
As I know there is workaround in which I can provide the link of pdf file to google url which will open pdf in webview. But it lags and is very slow.
Basic answer, no. You can't open a PDF in a webview; so you either need to fire an Intent to open the file (the file can then open in the default installed app on the device); or write your own PDF reader.
Try to use pdf.js.
See http://www.worldwidewhat.net/2011/08/render-pdf-files-with-html5/
I downloaded its source and placed it in sdcard.
Then I use a WebView to load its index.htm.
It did show pdf file on a webView in sdcard in Android 4.0 device but sometime it show white page. I need to reload it and it finally can show.
Unfortunately, I also tested on Android 2.2 and 2.3 devices. They just show white page, nothing.
I know it make use of html5 canvas technology. I have checked on loading http://html5test.com/ on WebView and have tick on canvas element but still can't show pdf. Strange behaviour. Maybe really depends on Android version.