Render only a portion of a PDF on iPhone/iPad
Posted
by Infinity
on Stack Overflow
See other posts from Stack Overflow
or by Infinity
Published on 2010-05-28T21:46:46Z
Indexed on
2010/05/28
21:52 UTC
Read the original article
Hit count: 258
objective-c
|iphone-sdk
Hello guys!
I am rendering my pdf in an UIView's drawRect method. Here's my code:
- (void)drawRect:(CGRect)rect2 {
NSString *filename = @"lol.pdf";
CFStringRef path = CFStringCreateWithCString (NULL, [filename UTF8String], kCFStringEncodingUTF8);
CFURLRef url = CFURLCreateWithFileSystemPath (NULL, path, kCFURLPOSIXPathStyle, 0);
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL(url);
CGPDFPageRef page = CGPDFDocumentGetPage (pdf, 1);
CGAffineTransform m;
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect aRect = CGRectMake(0, 0, 768, 1024);
CGContextTranslateCTM(context, 0.0, aRect.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
m = CGPDFPageGetDrawingTransform (page, kCGPDFMediaBox, aRect, 0, YES);
CGContextSaveGState (context);
CGContextConcatCTM (context, m);
CGContextClipToRect (context,CGPDFPageGetBoxRect (page, kCGPDFCropBox));
CGContextDrawPDFPage (context, page);
CGContextRestoreGState (context);
}
It renders the whole pdf. How can I render only a part from it? Can you help me with it?
© Stack Overflow or respective owner