本地导入PDF文件
一: 利用UIWebView加载
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[self.view addSubview:webView];
NSString *path = [[NSBundle mainBundle] pathForResource:@"基于Apache+JMeter" ofType:@"pdf"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
二:利用系统的预览文件的框架QuickLook
2.1、首先导入框架QuickLook.framework
2.2、引入头文件#import <QuickLook/QuickLook.h>
实例化对象
QLPreviewController *myQlPreViewController = [[QLPreviewController alloc]init];
myQlPreViewController.delegate =self;
myQlPreViewController.dataSource =self;
[myQlPreViewController setCurrentPreviewItemIndex:0];
//此处可以带导航栏跳转、也可以不带导航栏跳转、也可以拿到View进行Add
[self presentViewController:myQlPreViewController animated:YES completion:^{
NSLog(@"跳转完成");
}];
声明代理
<QLPreviewControllerDelegate,QLPreviewControllerDataSource>
实现协议
#pragma mark - QLPreviewController代理
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
return 1;
}
- (id<QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"基于Apache+JMeter" ofType:@"pdf"];
return [NSURL fileURLWithPath:path];
}
- (void)previewControllerDidDismiss:(QLPreviewController *)controller
{
NSLog(@"预览界面已经消失");
}
//文件内部链接点击不进行外部跳转
- (BOOL)previewController:(QLPreviewController *)controller shouldOpenURL:(NSURL *)url forPreviewItem:(id <QLPreviewItem>)item
{
return NO;
}
网友评论