打开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 documentsMicrosoft Office documents (Office ‘97 and newer)Rich Text Format

// (RTF) documentsPDF filesImagesText files whose uniform type identifier (UTI) conforms

//  to the public.text typComma-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)