Skip to content

Instantly share code, notes, and snippets.

@aquarla
Created May 21, 2010 12:08
Show Gist options
  • Save aquarla/408755 to your computer and use it in GitHub Desktop.
Save aquarla/408755 to your computer and use it in GitHub Desktop.
//
// 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