OC - 阅读PDF、docx、Excle等文件
2017-12-24 22:18
274 查看
今天给大家分享一下,阅读PDF等格式文件的原生方法,前两天给同事写了个Demo。
直接上代码了
//
// ViewController.m
// DemoForWord
//
// Created by 司小文 on 2017/11/30.
// Copyright © 2017年 司小文. All rights reserved.
//
#import "ViewController.h"
#import <QuickLook/QuickLook.h>
@interface ViewController ()<QLPreviewControllerDataSource>
@property (nonatomic,strong) QLPreviewController *qlpreviewController;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_qlpreviewController = [[QLPreviewController alloc] init];
_qlpreviewController.view.frame=CGRectMake(100, 100, 250, 500);;
_qlpreviewController.dataSource = self;
[_qlpreviewController refreshCurrentPreviewItem];
[self addChildViewController:_qlpreviewController];
[self.view addSubview:_qlpreviewController.view];
}
#pragma mark - qlpreViewdataSource
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
return 1;
}
- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
// 获取文件路径, 此处可以读取excle docx PDF等格式
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"demoForWord" ofType:@"docx"];
return [NSURL fileURLWithPath:filePath];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
这里是 demo的百度分享。
感谢观看,学以致用更感谢。
直接上代码了
//
// ViewController.m
// DemoForWord
//
// Created by 司小文 on 2017/11/30.
// Copyright © 2017年 司小文. All rights reserved.
//
#import "ViewController.h"
#import <QuickLook/QuickLook.h>
@interface ViewController ()<QLPreviewControllerDataSource>
@property (nonatomic,strong) QLPreviewController *qlpreviewController;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_qlpreviewController = [[QLPreviewController alloc] init];
_qlpreviewController.view.frame=CGRectMake(100, 100, 250, 500);;
_qlpreviewController.dataSource = self;
[_qlpreviewController refreshCurrentPreviewItem];
[self addChildViewController:_qlpreviewController];
[self.view addSubview:_qlpreviewController.view];
}
#pragma mark - qlpreViewdataSource
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
return 1;
}
- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
// 获取文件路径, 此处可以读取excle docx PDF等格式
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"demoForWord" ofType:@"docx"];
return [NSURL fileURLWithPath:filePath];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
这里是 demo的百度分享。
感谢观看,学以致用更感谢。
相关文章推荐
- Java平台要实现类似豆丁百度文科的文档在线阅读,总体思路是讲doc docx等文件格式利用jcom转换成pdf再用swftools转为swf。再用flexpaper组件显示swf。
- Java平台要实现类似豆丁百度文科的文档在线阅读,总体思路是讲doc docx等文件格式利用jcom转换成pdf再用swftools转为swf。再用flexpaper组件显示swf。
- 【Android】Android阅读各种格式文件(包括DOC/DOCX/WPS/XLS/XLSX/PPT/PPTX/TXT/PDF)
- Asp.net在线阅读文件(pdf,txt,doc,jpg等)
- Android:使用MuPdf开源库阅读PDF文件
- struts 文件下载——导出Excle/导出PDF
- Android 在webview中下载pdf文件,并用自定义界面阅读
- 在你的网页中嵌入PDF等文件,实现pdf在线阅读
- 在html页面中展示pdf文件,实现在线阅读
- docx、ppt、xls、pdf文件转html
- C# winform 实现PDF文件阅读
- HTML5在线PDF格式文件阅读器
- Android 实现 PDF 文件阅读功能调研
- 手机端 阅读 pdf 文件 touchPDF.js
- 文档在线阅读系列之——pdf文件转换为html
- iOS中查看&打印 .pdf .doc .docx文件
- Jasper6 导出Excle,PDF,World文件
- 自制适合IPAD阅读的PDF文件
- ASP.NET 用 Office COM 组件将 docx\pptx\xlsx 转换成 PDF 文件
- 实现在线阅读WORD,PDF等文件,JAVA,PHP都可以