在基于iOS cordova的应用程序中查看PDF文档的插件

在基于iOS cordova的应用程序中查看PDF文档的插件,ios,iphone,ios8,cordova-plugins,cordova-3.8.0,Ios,Iphone,Ios8,Cordova Plugins,Cordova 3.8.0,请推荐一个可以在基于iOS Cordova的应用程序中查看PDF的插件 I have tried many of PDF related plugins: https://github.com/siegfriedbolz/cordova-plugin-file-opener2.git https://github.com/RandyMcMillan/PDFViewer but of no use..My application stopped at loading. L

请推荐一个可以在基于iOS Cordova的应用程序中查看PDF的插件

  I have tried many of PDF related plugins:

  https://github.com/siegfriedbolz/cordova-plugin-file-opener2.git 
  https://github.com/RandyMcMillan/PDFViewer
   but of no use..My application stopped at loading.

 Lastly with I have tried with pebois/phonegap-plugin-PDFViewer:


  I have installed using : 
   "cordova plugin add com.lesfrancschatons.cordova.plugins.pdfreader" 


  In index.html:

  function onDeviceReady() 
        {

            PDFViewer.open("file://sample.pdf","sample.pdf", function (msg) {
                           console.log(msg);//
                           });
      }


//error on pdfviewer.open method
  • 谁能告诉我上述方法的问题是什么

  • 我们如何为sample.pdf提供路径(希望我给出了错误的路径)

  • 或者如果有iOS Cordova的PDF插件

我总是使用自己制作的“自制”插件;它通过单个get获取特定URL上的PDF

Pdfulities.m PDH
您是如何在ios中获取pdf文件的?我们正在通过服务器根据用户请求下载pdf文件后端,因为我有上述问题,我正在使用直接链接在应用程序中加载:$('scheduleTimingsRender').attr('onclick','navigator.app.loadUrl('+pdfLink+“,{openExternal:true}”);做一件事:使用“对象无法渲染”,并将您的pdf路径添加到对象内部的数据标记中。@Vishal谢谢。。我很高兴,我知道这意味着什么,如果您遇到科尔多瓦的麻烦;)
#import "PDFUtilities.h"


@interface PDFUtilities()

@property (strong, nonatomic) UIDocumentInteractionController *documentInteractionController;

@end


@implementation PDFUtilities

- (void)viewPdf:(CDVInvokedUrlCommand*)command
{   
    if (command.arguments[0] == (id)[NSNull null])
    {
        [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR] callbackId:command.callbackId];
        return;
    }

    NSString *url = command.arguments[0];

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND,(unsigned long)NULL), ^(void)
    {
        NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
        NSString *file = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"PDF.pdf"]];

        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

        [request setURL:[NSURL URLWithString:url]];
        [request setHTTPMethod:@"GET"];

        [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
        {
           NSLog(@"pdf downloaded, opening...");

           NSData *pdf = data;

           CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)pdf);
           CGPDFDocumentRef document = CGPDFDocumentCreateWithProvider(provider);

           if (document == nil) {
               // error
           }
           else 
           {
               NSURL *localURL = [NSURL fileURLWithPath:file];

               [pdf writeToFile:file options:NSDataWritingAtomic error:&error];

                self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:localURL];
               [self.documentInteractionController setDelegate:self];
               [self.documentInteractionController presentPreviewAnimated:NO];

           }

           CGDataProviderRelease(provider);
           CGPDFDocumentRelease(document);
        }]; 
    });

    [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] callbackId:command.callbackId];
}

- (UIViewController*) documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
    return  [[[[UIApplication sharedApplication] delegate] window] rootViewController];
}
#import <Cordova/CDVPlugin.h>

@interface PDFUtilities : CDVPlugin <UIDocumentInteractionControllerDelegate>

- (void)viewPdf:(CDVInvokedUrlCommand*)command;

@end
<feature name="PDFUtilities">
        <param name="ios-package" value="PDFUtilities" />
</feature>
cordova.exec(
            function(){},
            function(){},
            'PDFUtilities',
            'viewPdf',
            [urlpdf]
);