Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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.

— asked November 10th 2010 by chef koch
  • android
  • pdf
  • scrollableview
  • webview
0 Comments

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

    — answered December 7th 2010 by Dawson Toth
    permalink
    0 Comments
  • 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);
    
    — answered November 10th 2010 by Aaron Saunders
    permalink
    3 Comments
    • Are you running that code on Android or iPhone, Aaron?

      — commented November 10th 2010 by Dawson Toth
    • my code run on iphone but not on android…

      — commented November 12th 2010 by chef koch
    • the question referred to an Android phone

      — commented December 13th 2010 by Alberto Marcone
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.