0

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.

10
  • firstly the reason is that WebView can't open PDF itself. It doesn't support PDF. Your solutions firstly convert PDF into HTML page, and only after that - open that page in WebView. But who knows what can happen during conversion. Try checking logcat for any messages related to WebView. Commented Jan 23, 2018 at 11:49
  • Hi, thanks for the reply, bu there is no message related to WebView in my logcat, nothing strange, no crash, nothing. Simply sometime it open the PDF sometime not. Maybe i can try to open the PDF URL with a PDF Reader App installed on my Device? Really I can't understand why on iOS everything works fine and with Android there is not a default PDF Reader. It's insane! Commented Jan 23, 2018 at 12:03
  • open the PDF URL with a PDF Reader App is not a good idea I think. It's for the reason that you already know - there is not a default PDF Reader. for Android. And it is quite OK not to have it on the device - Windows does not have a PDF reader by default as well. You have to install one. Commented Jan 23, 2018 at 12:10
  • I'd suggest implementing PDF reading functionality in your app. There are already tones of libraries. Commented Jan 23, 2018 at 12:21
  • Tounes of libraries? Could you please link here some for Xamarin Forms? Thanks! Commented Jan 23, 2018 at 12:30

1 Answer 1

0

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:

  1. 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.
  2. 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.