iOS PDF转为相册图片
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS PDF转为相册图片相关的知识,希望对你有一定的参考价值。
参考知识1 //要跟据retina 屏幕做分辨率适配-(void)getUIImageFromPDFPage:(int)page_number filePath:(NSString*)pdfPath
NSURL*filePath = [NSURLfileURLWithPath:pdfPath];
//读取PDF原文件的大小
CGPDFDocumentRef doc = CGPDFDocumentCreateWithURL((__bridge CFURLRef)filePath);
CGPDFPageRefpage =CGPDFDocumentGetPage(doc,1);
CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
pageRect.origin=CGPointZero;
pageRect.size.height= pageRect.size.height*2;
pageRect.size.width= pageRect.size.width*2;
//开启图片绘制 上下文
UIGraphicsBeginImageContext(pageRect.size);
CGContextRef context =UIGraphicsGetCurrentContext();
// 设置白色背景
CGContextSetRGBFillColor(context,1.0,1.0,1.0,1.0);
CGContextFillRect(context,pageRect);
CGContextSaveGState(context);
//进行翻转
CGContextTranslateCTM(context, -pageRect.size.width/2, pageRect.size.height*1.5);
CGContextScaleCTM(context,2, -2);
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextSetRenderingIntent(context, kCGRenderingIntentDefault);
CGContextConcatCTM(context, CGPDFPageGetDrawingTransform(page, kCGPDFMediaBox, pageRect,0,true));
CGContextDrawPDFPage(context,page);
CGContextRestoreGState(context);
UIImage *pdfImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[selfsaveImage:pdfImage];
- (void)saveImage:(UIImage*)image
UIImageWriteToSavedPhotosAlbum(image,self,@selector(image:didFinishSavingWithError:contextInfo:), (__bridgevoid*)self);
- (void)image:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo
if(!error)
NSLog(@"成功");
else
NSLog(@"失败");
以上是关于iOS PDF转为相册图片的主要内容,如果未能解决你的问题,请参考以下文章