How to View a PDF which is inside a Webview?android - android

In my web-view I have a PDF forum If user makes any changes That will be added to PDF
But Here I am Unable to View That PDF In Webview
I have Tried with http://drive.google.com/viewerng/viewer?embedded=true&url=
But Its Opening My web page source Code... Only Half a part of my Webpage is PDF.. And renaming Is text-box etc..
like below
Here Pdf is showing in browser but not in my Web-view
Can any one help me I need to Show PDF and Add some changes all this in web-view please help me...
Update
In my webpage I am getting Pdf as a part of it not entire page as pdf is here its not working with http://drive.google.com/viewerng/viewer?embedded=true&url=
If I open My Web page in that url I am getting source code of my web page... Please help
Update 1
Here In the above Image...... PDF is not loading in webview only web page is loading but where as a in browser its loading Please help

The other GOOGLE-url.
Have you tried this suffix https://docs.google.com/gview?embedded=true&url=YOURURL ?

Are you redirecting to drive intentionally? You have to pass the correct .pdf url
https://docs.google.com/viewer?url=yoururl.pdf

This way, you can see the PDF inside your webview.
String pdfURL = "http://www.expertagent.co.uk/asp/in4glestates/{16D968D6198E-4E33-88F4-8A85731CE605}/{05c36123-4df0-4d7d-811c-8b6686fdd526}/external.pdf";
webView.loadUrl("http://docs.google.com/gview?embedded=true&url=" + pdfURL);

Related

Pdf file is not able to load in android webview but able to load in external browser

I have the webpage created with angular js file. There are pdf files inside the webpage we want to download and show.
when clicking the pdf file, it just show loading and nth happened. Also shouldOverrideUrlLoading method is never called. This method is not deprecated.
We tried to load the url in external browser and open the pdf, it successfully download and open the pdf file.
I would like to know is there any webview setting I missed out?
current webview settings in my implementation is as below . Kindly help. thank you
webView?.settings?.builtInZoomControls = true
webView?.settings?.domStorageEnabled = true
webView?.settings?.allowFileAccess = true
webView?.settings?.allowContentAccess = true
You should try this one might be it work by WebViewClient.
Check out this -- https://stackoverflow.com/a/14201778/18858169
PDF is a file format NOT handled by WebView, it's designed to show web content, not some documents
if you really want to show PDF inside WebView then you should use some web application, which can take a PDF file (or URL pointing on some) and render content of your file in a "web way", thus WebView could print it
for example Google have such web app and you can open PDFs in it using some of below URLs (these may changed)
https://docs.google.com/viewer?url=http://customdomain.com/pdffile.pdf
https://docs.google.com/gview?embedded=true&url=http://customdomain.com/pdffile.pdf
https://drive.google.com/viewerng/viewer?embedded=true&url=http://customdomain.com/pdffile.pdf
note that you are basing on 3rd-party service - your PDF may be online, but 3rd-party companys server-side may be down or changed routing and your hardcoded URL prefix stop working
and if you want to show "real" PDF then use PdfRenderer class, which will give you a set of Bitmaps, which can be shown with ImageView, no WebView needed

Forms, Open PDF from URL

I'm using Xamarin Forms with Android, I need to open a PDF from an URL in my WebView. For some reason, sometime the the Webview is blank. I've searched a lot on Internet and I found some solution that give me the same result, sometime the PDF in the PDF is showed without problem, sometime is a blank page. I'm using "https://drive.google.com/viewerng/viewer?embedded=true&url=" with no results, I'm using this solution ( https://acaliaro.wordpress.com/2017/11/30/open-a-pdf-inside-a-webview-in-xamarin-forms-android/ ) that describe exactly my problem but WebView still show me a blank page sometime.
So, why is so hard to open a PDF Url on Android in a WebView? There is some solution to fix this problem? I don't know what can i else do.
Android WebView not support .pdf file from website, infact, if you try to copy an url with .pdf extension in chrome browser, this will download the file and open in an app. So there is no way to show a PDF in an App in a simple way. But there are two solution:
On Google there are a lot solutions that tells you to download the PDF and show in an webview, but in my case I can't download a PDF and show.
You can write an .html page in your Server that can "wrap" the PDF sended with an URL in GET mode and show it in an .html page without problem ( using jsPDF is an example ) or by using this prefix ( http://drive.google.com/viewerng/viewer?embedded=true&url= ) but sometime i give a blank page, so i write my own pdf viewer. In this link ( https://acaliaro.wordpress.com/2017/11/30/open-a-pdf-inside-a-webview-in-xamarin-forms-android/ ) you can find another solution, but for some reason, it still doesn't works. Maybe because I'm on Android 5.0 device.

Viewing PDF from URL using Adobe in Android

I'm just learning Android code and I've come upon a problem which I hope you can all help.
I want to display a PDF file from a URL from my application, I've got the PDF to display using a webView method however with having Adobe Reader and Polaris Office installed on my phone I was just wondering if I can load the URL and implement the PDF to be displayed using installed software?
My webView code is as follows:
WebView web = (WebView) findViewById(R.id.webView);
web.getSettings().setJavaScriptEnabled(true);
String pdf = "http://www.example-site.co.uk/pdf";
web.loadUrl("http://docs.google.com/gview?embedded=true&url=" + pdf);
I have searched several posts on here to no avail so any help will be much appreciated.
Searching for "pdf view intent" reveals stuff like that: How to render PDF in Android
If that doesn't help, you should try to implement a IntentChooser or directly ask the devs of your two apps on which intent they are listening.

can we render pdf on web view in android

can we render pdf and show it on web view in android. kindly help me out
Yes you can load PDF in Webview using Google's gview, It is a trick.
Here you can have my solution for the same trick: Android - Load PDF / PDF Viewer.
You cant open PDF file directly in android web browser but using Google Docs Viewer. you can open it in android Browser like:
String webUrl="http://myweb.com/demo.pdf";
mWebView.loadUrl("https://docs.google.com/gview?embedded=true&url="+ webUrl);
Unluckily, Google has changed the api... When you try to load the docs.google.com/gview url, the web view is redirect to the new drive.google.com/viewerng that can't render the pdf in the Android WebView...
Any other clever solution? :D

Android - Load PDF / PDF Viewer

I want to display pdf contents on webview.
Here is my code:
WebView webview = new WebView(this);
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("URL/Demo_PDF.pdf");
Problem:
When i am trying to run the application, at that time I am getting blank screen.
And also, if there is any PDF viewer then also suggest me !!
FYI, I have already set internet permission.
Finally, i got a solution, actually i made a trick to load a pdf file using Google Docs inside a webview:
webview.loadUrl("http://docs.google.com/gview?embedded=true&url=http://myurl.com/demo.pdf");
I'm sorry but WebView does not display PDF content.
What you might want is a PDF viewer that responds to the PDF MIME type.
Here are a couple of free open-source libraries you might want to check:
droidreader
apv pdf reader
You can try using mupdf (www.mupdf.com)
You can build a native code library (libmupdf.so) to be loaded onto your android project using the ndk.
This would ensure a lot faster rendering of pdf files...
check out the project at : http://mupdf.com/repos/mupdf/android/
WebView does not have a PDF plugin. You should store the PDF locally and open an intent for viewing that kind of content.

Categories

Resources