Open Pdf In The Phonegap App That Is Made In Html And Css
Solution 1:
Try using the In App Browser plugin.
If you're using a later Phonegap / Cordova version (2.8.0, 2.9.0 etc) it should come with it - nothing else to install.
http://docs.phonegap.com/en/2.9.0/cordova_inappbrowser_inappbrowser.md.html#InAppBrowser
It will allow you to open the PDF in the a new 'window' that overlays your app. It has a 'Done' button that users can use to close it and return to your app when they are finished.
You would open the PDF using the In-App Browser, using something like this:
window.open('http://whitelisted-url.com/pdftoopen.pdf', '_blank');
I.e. the _blank
option triggers the In-App Browser plugin. If you were to use _system
instead it might open it in iBooks (just guessing there - not 100% sure if it would use iBooks).
Solution 2:
Try prefixing https://docs.google.com/viewer?url=
in the URL
like, window.open('https://docs.google.com/viewer?url=http://www.example.com/example.pdf&embedded=true', '_blank', 'location=yes');
Solution 3:
Try this to open any kind of documents from URL using following steps:
- install this plugin : cordova plugin add https://github.com/ti8m/DocumentHandler
use this code :
handleDocumentWithURL(function() { console.log('success'); }, function(error) { console.log('failure'); if (error == 53) { console.log('No app that handles this file type.'); } }, 'http://www.example.com/path/to/document.pdf');
It works for me both on Android and IOS. I used it for open images and PDF files.
Android : It opens files using system apps if available, otherwise it give an error, which you can handle.
IOS : It opens files in popup like view with Done button and Option button.
It doesn't show your docs URL.
Source is available here : https://github.com/ti8m/DocumentHandler
Solution 4:
Thanks asgeo1,
I solved it by using window.open()
.
<ahref="#"onclick="window.open('http://12example.pdf', '_blank', 'location=no');"><imgsrc="images/samplens.jpg"border="0" /></a>
Hope it helps.
Solution 5:
I've ended up using WebIntent
as described here. The tricky part was to modify WebIntent.java to properly identify file type:
Stringtype = obj.has("type") ? obj.getString("type") : null;
// New code starts Uri uri = obj.has("url") ? Uri.parse(obj.getString("url")) : null;
String extension = MimeTypeMap.getFileExtensionFromUrl(obj.getString("url"));
if(extension != null){
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
type = mimeTypeMap.getMimeTypeFromExtension(extension);
}
// New code ends JSONObject extras = obj.has("extras") ? obj.getJSONObject("extras") : null;
Post a Comment for "Open Pdf In The Phonegap App That Is Made In Html And Css"