Monday 8 July 2013

How to use iOS DocumentViewer .

// iOS DocumentViewer is very helpful to open .pdf file in appcelerator in iOS.

Prefer below link it gives whole description of iOS DocumentViewer.

// http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.iOS.DocumentViewer

For example, an email program might use this class to allow the user to preview attachments and open them in other apps. Use this class to present an appropriate user interface for previewing or printing a specified file. 

Sample Code  :)

app.js 

var win1 = Titanium.UI.createWindow({
    title : 'win 1',
    backgroundColor : '#fff'
});
var modalWin = Ti.UI.createWindow();

var navmodal = Ti.UI.iPhone.createNavigationGroup({
    window : modalWin
});
win1.add(navmodal);

var b2t = Titanium.UI.createButton({
    title : 'Open PDF'
});
modalWin.RightNavButton = b2t;

var b1t = Titanium.UI.createButton({
    title : 'Share PDF',
    height : 40,
    width : 200,
    top : 270
});
win1.add(b1t);

z = Ti.UI.iOS.createDocumentViewer({
    url : 'GettingStarted.pdf' // Name of PDF file and path is simply in iphone folder
});

b1t.addEventListener('click', function() {
    z.show({
        animated : false,
        view : b2t
    });
});

b2t.addEventListener('click', function() {
    z.show();
});
win1.open();

Snap :)







No comments:

Post a Comment