打开PDF 需要的库QuickLook.framework

本文介绍了一个用于iOS设备上预览PDF文件的方法。通过使用QuickLook.framework框架,可以轻松实现多种文件格式的预览功能,包括但不限于PDF、iWork文档、Microsoft Office文档等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值