Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed PDF Viewer for PhoneGap application

How can I embed a PDF viewer for a phonegap application? I have decided to use PhoneGap + Sencha Touch to develop an application for iOS and Android.

like image 255
JohanSJA Avatar asked Aug 08 '11 08:08

JohanSJA


1 Answers

I only have iOS phonegap experience. The solution that has worked for me is to make a plugin that pops up a native webview that uses iOS native pdf viewer. The way to get this to work is to follow the instructions on this website.

http://spin.atomicobject.com/2010/12/07/updating-phonegap-s-childbrowser-plugin-to-handle-local-files/

This link modifies an existing plugin, "Child browser" to use the native webview display pdf's. The original chilbrowser plugin can be found here.

To give you more of an idea of what it will be like, here is my particular javascript call that I put into my sencha application.

 PhoneGap.exec("ChildBrowserCommand.showFilePage", GlobalVar.localRoot + "/" + record.get("FilePath"));

This is inside the handler for the buttonTap inside the sencha, pressing the button will then call the objective C method "showFilePage". The parameter is the filepath that the plugin will use.

Here is the Objective C part (again, you should follow the links for full instructions)

    - (void) showFilePage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options // args: url
{   
    NSLog(@"showFilePage entered: ");
    if(childBrowser == NULL)
    {
        childBrowser = [[ ChildBrowserViewController alloc ] initWithScale:FALSE ];
        childBrowser.delegate = self;
    }




    PhoneGapViewController* cont = (PhoneGapViewController*)[ super appViewController ];
    childBrowser.supportedOrientations = cont.supportedOrientations;
    [ cont presentModalViewController:childBrowser animated:YES ];

    NSString *path = (NSString*) [arguments objectAtIndex:0];
    NSLog(@"Our argument 0 is: %@",[arguments objectAtIndex:0]);

    NSLog(@"The url is: %@",path);
    [childBrowser loadFileURL:path];

}
like image 199
hatunike Avatar answered Sep 20 '22 08:09

hatunike