Created
May 21, 2010 12:08
-
-
Save aquarla/408755 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// PDFView.m | |
// PDFViewerSample | |
// | |
#import "PDFView.h" | |
@implementation PDFView | |
- (id)initWithFrame:(CGRect)frame { | |
if ((self = [super initWithFrame:frame])) { | |
self.backgroundColor = [UIColor whiteColor]; | |
} | |
return self; | |
} | |
// Only override drawRect: if you perform custom drawing. | |
// An empty implementation adversely affects performance during animation. | |
- (void)drawRect:(CGRect)rect { | |
CGPDFDocumentRef document; | |
int count; | |
CGContextRef myContext = UIGraphicsGetCurrentContext(); | |
NSString *pathNSString = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"pdf"]; | |
document = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL fileURLWithPath:pathNSString]); | |
count = CGPDFDocumentGetNumberOfPages(document); | |
if (count == 0) { | |
NSLog(@"PDFファイルじゃないよ"); | |
return; | |
} | |
CGContextTranslateCTM(myContext, 0, rect.size.height); | |
CGContextScaleCTM(myContext, 1.0, -1.0); | |
CGPDFPageRef page = CGPDFDocumentGetPage(document, 1); | |
CGContextDrawPDFPage(myContext, page); | |
CGContextFlush(myContext); | |
} | |
- (void)dealloc { | |
[super dealloc]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment