pdf in webview in scrollableview on android
Hi people
Here is my code:
var win = Titanium.UI.currentWindow;
var view1 = Titanium.UI.createWebView({url:'http://www.x.com/x.pdf'});
var scrollView = Titanium.UI.createScrollableView({
views:[view1]
});
win.add(scrollView);
The Pdf won't load/show.
Can anyone help me?
Thanks.
3 Answers
-
iPhone's web views support PDFs. Android's do not.
I hope you have gotten that answer in the last four weeks, but just in case you have not… To view a PDF on Android, the phone needs to download the PDF and then launch a 3rd party app like Adobe Reader or ThinkFree Office – one usually comes bundles with the phone. So to open a PDF on Android, you need to call:
Ti.Platform.openURL('http://your.com/your.pdf');
I wrote about some additional gotchas related to this on a different Q&A, including workarounds for all of them. (Hint: The above code won't work on some HTC Android devices, because the proper intents are not set.)
http://developer.appcelerator.com/question/72361/open-pdf-file-on-android
-
You can view PDFs in Android by utilizing Android Intents. This blog post shows you exactly how to do this with Titanium: http://developer.appcelerator.com/blog/2011/09/sharing-project-assets-with-android-intents.html
-
Just tested this code and it works, down know if there is a problem with your URL or something. I would suggest testing the URL but the code you have provided looks correct
var win2 = Titanium.UI.createWindow({ title : 'Test PDF', backgroundColor : '#fff' }); var webview0 = Titanium.UI.createWebView({ url : 'http://assets.appcelerator.com.s3.amazonaws.com/docs/API_UITableViewClass.pdf' }); var webview1 = Titanium.UI.createWebView({ url : 'http://assets.appcelerator.com.s3.amazonaws.com/docs/API_TitaniumModule.pdf' }); var scrollView = Titanium.UI.createScrollableView({ views:[webview0,webview1] }); win2.add(scrollView);