`
13146489
  • 浏览: 246827 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

显示PDF

阅读更多
UIWebView:方便快捷,因此也就效率慢。
QLPreviewController和UIDocumentInteractionController:底层使用UIWebView,但是提供预览模式。
CGPDFDocument:较底层方法,当然需要不少代码。
重要:官方demo->ZoomingPdfViewer(一切都在里面)
资料:
1、http://stackoverflow.com/questions/4121674/is-there-any-best-way-to-show-pdf-in-iphone-other-than-uiwebview-in-objective-c
    It sounds like you may have some large vector calculations going on in your PDF. You can try re-constructing your PDF with flat images instead of vectors.

Code-wise QLPreviewController should be able to do what you want with a PDF, however it may use a UIWebView underneath. UIDocumentInteractionController also has a preview mode, but I suspect that it is using a QLPreviewController itself for it's preview.

You can also use the low level PDF functions, though this will be more difficult to do. Look at CGPDFDocument and it's related APIs in apple's documentation for more here.

2、http://zhao-zhe.appspot.com/?p=139001
文章在该网页的较底部。多找找。标题是:2,预览pdf等文本文件与图片

iOS4中新增了类QLPreviewController,可以用于预览iWork documents,MS Documents,RTF,PDF,Images,CSV等文件.它包含在QuickLook.framework中,使用时需要包含头文件<QuickLook/QuickLook.h>.使用QLPreviewController需要实现代理QLPreviewControllerDelegate,QLPreviewControllerDataSource.
//
//  YQuickLook.h
//  YouX
//
//  Created by zhezhao on 10-12-1.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <QuickLook/QuickLook.h>

@interface YQuickLook : NSObject <QLPreviewControllerDelegate,QLPreviewControllerDataSource>{
NSArray *paths;
}

@property (nonatomic, retain) NSArray *paths;

@end
//
//  YQuickLook.m
//  YouX
//
//  Created by zhezhao on 10-12-1.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "YQuickLook.h"


@implementation YQuickLook
@synthesize paths;

- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller{
return [paths count];
}

- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index{
NSURL *url = [NSURL fileURLWithPath:[paths objectAtIndex:index]];
return url;
}

- (void)dealloc {
[super dealloc];
[paths release];
}
@end
调用方法:
QLPreviewController *controller = [[QLPreviewController alloc] init];
YQuickLook *quickLook = [[YQuickLook alloc] init];
quickLook.paths = [NSArray arrayWithObjects:attachment.path,nil];
controller.delegate = quickLook;
controller.dataSource = quickLook;
[self.navigationController pushViewController:controller animated:YES];
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics