inAppBrowser ANDROID reading PDF problems - android

Coming here, desperately, I really need help with an answer for my question... I do have a inAppBrowser and my can't ready a PDF (after accessing pdf view). I use cordova, phonegap. I know that I can't read a PDF because for android IAB didn't implemented a viewer, but, how can i use plugin FileTransfer? or open(url, _system). From the start, I call my app as open(url, _blank). If I'm pressing on PDF link, want my IAB to be transformed in _system, but when I go back, want my app still be _blank. Or, if I'm accessing a PDF link, to be downloaded, using FileTransfer. I had tried this 2 codes:
FileTransfer:
var fileTransfer = new FileTransfer();
fileTransfer.download(url, "");
If I'm accessing PDF link, nothing happens...
And _system:
cordova.InAppBrowser.open(url, '_system', 'location=no');
This code works fine, but! After I'm accessing PDF link, IAB -> transforms into _system, but when I go back and I press on PDF link again, nothing happens anymore... (so what I want is my IAB, to be _blank again)
Thank you !

Related

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.

Android website in webview, open file upload dialog

I have a webview that points to a website:
webView.loadUrl("https://websmash.herokuapp.com/");
When the user clicks on a file upload button in the website it should open a file upload dialog on the phone.
Matt Gaunt has provided a fully-functional example using onShowFileChooser(), although the file upload button is in the local index.html file. I've been trying to get this working for a website inside the webview, but to no avail.
What adaptations must be made to get it working when the button is in the website which the webview points to?
Take a look at this SO Post. Per the author`s answer code works for all android versions.

Document Viewer for phonegap Applications

Have anyone used Childbrowsers or InAppBrowser plugin for pdf/anydoc viewer in android...IF so how does it work..I need to develop a document viewer for my phonegap Application...Plz suggest something..Thanks :)
Please look at the provided documentation or tells us what you have tried
InAppBrowser is a built in plug-in for the standard phonegap release since version 2.3.0.
Childbrowser was used for version previous to that as a non default plug-in.
Documentation is on the phonegap website
http://docs.phonegap.com/en/2.5.0/cordova_inappbrowser_inappbrowser.md.html#InAppBrowser
Andrdoid does not come with a default PDF viewer. So you may need to open your docs using google document reader and display in your InAppBrowser.
For everybody who is stuck with this problem here is what i´ve finally found out:
HTML 5 object tag: not working
Embedded tag: not working
childBrowser Plugin: I think it would work, but it is designed for the 2.0.0 version. So you´ll get a lot of errors so i didn´t get it to work.
Phonegap InAppViewer: If you use it like that:
window.open('http://www.example.com/test.pdf', '_blank', 'location=yes')
it wont work. The InAppViewer can´t open PDF, it doesn´t matter if the PDF is external or local stored.
My solutions so far (not what the actual idea was):
you can call the window function with _system. like that:
window.open('http://www.example.com/test.pdf', '_system', 'location=yes')
this will open the PDF in the normal Browser and download it. After downloading it will ask if it should open it with a PDF viewer. But you have to go back to your app and open it again after that.
Another possibility would be that you just download it to your sdcard with the Phonegap Filesystem API like that:
var fileTransfer = new FileTransfer();
fileTransfer.download(
"http://developer.android.com/assets/images/home/ics-android.png",
"file://sdcard/ics-android.png",
function(entry) {
alert("download complete: " + entry.fullPath);
},
function(error) {
alert("download error source " + error.source);
alert("download error target " + error.target);
alert("upload error code" + error.code);
});
The last thing i´ve found out is, to use Google docs/drive to open it with the InAppViewer linked to google docs like that:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
window.open('https://docs.google.com/viewer?url=http://www.example.com/test.pdf&embedded=true', '_blank', 'location=yes');
ref = window.open('index.html', '_self');
}
This will open the PDF in the app viewing it on google docs. You can generate your permalink here: https://docs.google.com/viewer So even if you change your pdf file, it will still work
I hope this summary will help you save time. If there is another solution let me know

New generated PDF is not shown in webView using google docs viewer using android

The problem i got in showing PDF is that it will show the old PDF view as i have created new PDF in server. it is not refreshing it . sometimes it show the correct PDf and sometimes it shows the previous generated PDf. As i have deleted the previous Pdf from the server through coding and genrate new PDf through coding but still it shows the old PDF that is not available in webView.I have checked the server database the old file is deleted and new is generated and there is no issue generatin and deleting in server database but with web view or google docs. I have used clear cache , clear history in webview but still its not working.
Please help.
Thanks
As you have already mention that you have used clear cache and clear history it should work. It is strange that it's not working.
You can check one of the following and try:
first put the URL inside the your PC browser and check whether correct pdf is opening if there the proper pdf opening then inside the Mobile browser that pdf has to open.
Inside the mobile go to the setting - Application - Manage Application - Go to your application from there unchecked all the option means(Force stop,clear data, clear cache) and now check once again.
Hope now it works. May be because the page it is stored inside the mobile browser cache that's why it giving such unexpected behavior.

Open a pdf file inside a webview.

I have an app where I've button on a webpage that is rendered inside a webview.
Now on click of button , a pdf file gets downloaded , and the same would then need to be opened inside the same webview.
attach a download listener to the web view and change the url as follows..
"https://docs.google.com/gview?embedded=true&url=https://www.example.com/xxxxxyyyyyxz.pdf"
example
https://docs.google.com/gview?embedded=true&url=https://www.adobe.com/support/products/enterprise/knowledgecenter/media/c4611_sample_explain.pdf
it's a link used to open pdf without downloading it...
I hope it solves your problem..
I've found that the google viewer seems to work within the android browser for viewing online PDF files. You could build a link to your pdf so that it is displayed in the viewer. I've not tried doing that within a WebView though.
UPDATE
The link is dead, there is an explanation of how to get the functionality to still work at this link.
In case this link also dies, here is the relevant section:
While the page is no longer available as it redirects to Google Docs/Drive, you can still use the Google Docs Viewer. Paste this URL in a new tab:
https://docs.google.com/viewer?url=
and then paste the address of the document you want to view online. Here's an example:
https://docs.google.com/viewer?url=http://research.google.com/archive/bigtable-osdi06.pdf
I do not think that the present android chrome based browser can support pdf. There are discussion about the same in android forums ( ex: link1 link2)
Your best bet to show pdf is to have adobe pdf reader for android installed.(or concisely put, not possible in web view)
I don't think any browser other than Chrome supports rendering PDFs without a plugin or third party tool. It's probably easier to let the user use his own app to open PDFs.
I used the IText PDF library mentioned in this thread
Android : Is there any free PDF library for Android for a sample project. You could try getting using this API to get the PDF page as an image. I am not familiar with every aspect of Itext so it might have better way to do this.

Categories

Resources