iphone pdf 解析
来源:互联网 发布:淘宝交易怎么免手续费 编辑:程序博客网 时间:2024/06/05 22:55
#import <UIKit/UIKit.h>
@class PDFTestViewController;
@interface PDFView : UIView {
//这个类封装了PDF画图得所有信息
CGPDFDocumentRef pdf;
//PDFDocument 中得一页
CGPDFPageRef page;
//总共页数
int totalPages;
//当前得页面
int currentPage;
PDFTestViewController *pdftest;
}
@property(nonatomic,retain)IBOutlet PDFTestViewController *pdftest;
//当前视图初始化类,在该方法中会创建一个CGPDFDocuemntRef对象,传递一个PDF文件得名字,和所需要页面得大小,
- (id)initWithFrame:(CGRect)frame andFileName:(NSString *)fileName;
//创建一个PDF对象,此方法在初始化方法中被调用
- (CGPDFDocumentRef)createPDFFromExistFile:(NSString *)aFilePath;
-(void)reloadView;
/*
页面之间得跳转
*/
-(void)goUpPage;
-(void)goDownPage;
@end
//
// PDFView.m
// PDFViewTest
//
// Created by Evan Lynn on 10-6-20.
// Copyright 2010 Tera Age. All rights reserved.
//
#import "PDFView.h"
//#import "PDFTestViewController.h"
@implementation PDFView
@synthesize pdftest;
- (id)initWithFrame:(CGRect)frame andFileName:(NSString *)fileName{
if (self = [super initWithFrame:frame]) {
NSString *dataPathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];
pdf = [self createPDFFromExistFile:dataPathFromApp];
self.backgroundColor = [UIColor clearColor];
}
return self;
}
- (CGPDFDocumentRef)createPDFFromExistFile:(NSString *)aFilePath{
CFStringRef path;
CFURLRef url;
CGPDFDocumentRef document;
path = CFStringCreateWithCString(NULL, [aFilePath UTF8String], kCFStringEncodingUTF8);
url = CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, NO);
CFRelease(path);
document = CGPDFDocumentCreateWithURL(url);
CFRelease(url);
totalPages = CGPDFDocumentGetNumberOfPages(document);
currentPage=1;
if (totalPages == 0) {
return NULL;
}
return document;
}
- (void)drawRect:(CGRect)rect {
//得到绘图上下文环境
CGContextRef context = UIGraphicsGetCurrentContext();
//得到一个PDF页面
page = CGPDFDocumentGetPage(pdf, currentPage);
/*进行坐标转换向右移动100个单位,并且向下移动当前视图得高度,
这是因为Quartz画图得坐标系统是以左下角为开始点,但iphone视图是以左上角为开始点
*/
CGContextTranslateCTM(context, 100.0,self.bounds.size.height);
//转变坐标系
CGContextScaleCTM(context, 1.0, -1);
CGContextDrawPDFPage(context, page);
}
- (void)dealloc {
[super dealloc];
}
-(void)reloadView{
[self setNeedsDisplay];
}
-(void)goUpPage{
if(currentPage < 2)
return;
--currentPage;
[self reloadView];
}
-(void)goDownPage{
if(currentPage >=totalPages)
return;
++currentPage;
[self reloadView];
}
- iphone pdf 解析
- pdf解析
- 解析pdf
- iPhone开发资源PDF电子书
- iPhone开发实战 pdf电子书
- 开源Android pdf 解析
- 解析pdf,获得内容
- Java解析 PDF
- android解析pdf文档
- android pdf解析
- PDFBox 解析PDF文档
- Android pdf解析方案
- 解析pdf文档
- PDFBox解析PDF文档
- PyPDF2解析pdf文件
- pdf文档解析
- java解析pdf文件
- python解析pdf文件
- TCP/IP体系结构-测试人员必须理解的
- TCP/IP学习笔记:组播
- source insight 配置
- 如何在ext中关闭子窗口
- C#:USB设备枚举(六)生成ListView数据源
- iphone pdf 解析
- jsp自定义标签晋级【实现循环输出】
- WPF-WPF BitmapEffect (按钮凹凸效果)
- java认证:客户端套接字(Socket)的超时
- java操作JSON数据格式
- errno入门
- C#:USB设备枚举(七)WPF扩展方法
- TCP/IP学习笔记:RIP
- gethostbyname() -- 用域名或主机名获取IP地址