本文主要是介绍打开PDF 需要的库QuickLook.framework,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
http://blog.sina.com.cn/s/blog_7fa6b06f0101dh1b.html
打开PDF 需要的库QuickLook.framework
//得到文件存放路径
-(NSString*)GetKnowledgeFileFullPath:(NSString*)FileName
{
@try {
// 文件存放目录
NSString *pngDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSError *err;
[fileMgr createDirectoryAtPath:pngDir withIntermediateDirectories:YES attributes:nil error:&err];
NSString *FileFullPath = [pngDir stringByAppendingPathComponent:FileName];
return FileFullPath;
}
@catch (NSException *exception) {
return nil;
}
@finally {
}
}
//根据路径预览文件
//===========================================================================
// 预览指定的文件
// (支持iWork documents、Microsoft Office documents (Office ‘97 and newer)、Rich Text Format
// (RTF) documents、PDF files、Images、Text files whose uniform type identifier (UTI) conforms
// to the public.text typ、Comma-separated value (csv) files)
//===========================================================================
- (void)PreviewKnowledge:(NSString*)KnowledgeFullPath
{
@try {
QLPreviewController *previewoCntroller = [[QLPreviewController alloc] init];
BZPreviewDataSource *dataSource = [[BZPreviewDataSource alloc]init];
dataSource.path = [[NSString alloc] initWithString:KnowledgeFullPath];
previewoCntroller.dataSource = dataSource;
[previewoCntroller setTitle:@"test"];
previewoCntroller.navigationItem.rightBarButtonItem=nil;
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version >= 5.0){
//此函数是5.0之后的函数。
[self presentViewController:previewoCntroller animated:YES completion:nil];
}
else {
//[self presentModalViewController:previewoCntroller animated:YES];
[self.navigationController pushViewController:previewoCntroller animated:YES];
}
}
@catch (NSException *exception) {
[Logger WriteLog:__FILE__ funcName:__func__ lineNum:__LINE__ exceptionObj:exception textInf:NULL];
}
@finally {
}
}
//BZPreviewDataSource类
//类的头文件
#import <Foundation/Foundation.h>
#import <QuickLook/QuickLook.h>
@interface BZPreviewDataSource : NSObject<QLPreviewControllerDataSource>
@property (nonatomic, retain) NSString *path;
@end
//类的实现
#import "BZPreviewDataSource.h"
@implementation BZPreviewDataSource
@synthesize path = _path;
- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller
{
return 1;
}
- (id <<span style="color: #7340a3">QLPreviewItem>)previewController: (QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
return [NSURL fileURLWithPath:_path];
}
@end
这篇关于打开PDF 需要的库QuickLook.framework的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!