Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- +(UIImage *)createPDFThumb:(NSString *)pdfURL thumbSize:(CGSize)thumbSize {
- NSURL *url = [NSURL URLWithString:pdfURL];
- CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef) url);
- CGPDFPageRef page;
- CGRect aRect = CGRectMake(0, 0, thumbSize.width, thumbSize.height);
- UIGraphicsBeginImageContext(aRect.size);
- CGContextRef context = UIGraphicsGetCurrentContext();
- UIImage* thumbnailImage;
- NSUInteger totalNum = CGPDFDocumentGetNumberOfPages(pdf);
- for (int i = 0; i < totalNum; i++ ) {
- CGContextSaveGState(context);
- CGContextTranslateCTM(context, 0.0, aRect.size.height);
- CGContextScaleCTM(context, 1.0, -1.0);
- CGContextSetGrayFillColor(context, 1.0, 1.0);
- CGContextFillRect(context, aRect);
- // Grab the first PDF page
- page = CGPDFDocumentGetPage(pdf, i + 1);
- CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFMediaBox, aRect, 0, true);
- // And apply the transform.
- CGContextConcatCTM(context, pdfTransform);
- CGContextDrawPDFPage(context, page);
- // Create the new UIImage from the context
- thumbnailImage = UIGraphicsGetImageFromCurrentImageContext();
- CGContextRestoreGState(context);
- }
- UIGraphicsEndImageContext();
- CGPDFDocumentRelease(pdf);
- return thumbnailImage;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement