Ios 从PDF Objective-C生成高质量的缩略图
我能够从pdf文档生成pdf缩略图图像。但问题是,我在图像的顶部和底部获得了Ios 从PDF Objective-C生成高质量的缩略图,ios,objective-c,pdf-generation,core-graphics,Ios,Objective C,Pdf Generation,Core Graphics,我能够从pdf文档生成pdf缩略图图像。但问题是,我在图像的顶部和底部获得了空白,而且我还更改了xy坐标值,但这对我不起作用 而且我得到的低质量y图像意味着这些图像看起来不好 在iBook中,pdf缩略图看起来太好了。所以我想生成那种缩略图 这是密码 -(NSMutableArray *)generateThumbnail:(NSMutableArray *)arrayDocuments { NSMutableArray* arrayOfImages = [[NSMutableArray
空白
,而且我还更改了xy坐标
值,但这对我不起作用
而且我得到的低质量
y图像意味着这些图像看起来不好
在iBook
中,pdf缩略图看起来太好了。所以我想生成那种缩略图
这是密码
-(NSMutableArray *)generateThumbnail:(NSMutableArray *)arrayDocuments
{
NSMutableArray* arrayOfImages = [[NSMutableArray alloc] init];
for (int i = 0; i < [arrayDocuments count]; i++) {
NSString* fileName = [arrayDocuments objectAtIndex:i];
NSString *filePath = [[NSBundle mainBundle]pathForResource:fileName ofType:nil];
NSURL* pdfFileUrl = [NSURL fileURLWithPath:filePath];
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfFileUrl);
CGPDFPageRef page = CGPDFDocumentGetPage(pdf, 0 + 1);
CGRect aRect =CGRectMake(0, 0, 100, 100);
UIGraphicsBeginImageContext(aRect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
UIImage* thumbnailImage;
CGContextSaveGState(context);
CGContextTranslateCTM(context, 0.0, aRect.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextSetGrayFillColor(context, 1.0, 1.0);
CGContextFillRect(context, aRect);
CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFMediaBox, aRect, 0, true);
CGContextConcatCTM(context, pdfTransform);
CGContextDrawPDFPage(context, page);
thumbnailImage = UIGraphicsGetImageFromCurrentImageContext();
[arrayOfImages addObject:thumbnailImage];
CGContextRestoreGState(context);
UIGraphicsEndImageContext();
CGPDFDocumentRelease(pdf);
}
return arrayOfImages;
}
-(NSMutableArray*)生成缩略图:(NSMutableArray*)数组文档
{
NSMutableArray*arrayOfImages=[[NSMutableArray alloc]init];
对于(int i=0;i<[arrayDocuments计数];i++){
NSString*fileName=[arrayDocuments对象索引:i];
NSString*filePath=[[NSBundle mainBundle]pathForResource:类型的文件名:nil];
NSURL*pdfFileUrl=[NSURL fileURLWithPath:filePath];
CGPDFDocumentRef pdf=CGPDFDocumentCreateWithURL((CFURLRef)pdfFileUrl);
CGPDFPageRef page=CGPDFDocumentGetPage(pdf,0+1);
CGRect aRect=CGRectMake(0,0,100,100);
UIGraphicsBeginImageContext(aRect.size);
CGContextRef context=UIGraphicsGetCurrentContext();
UIImage*缩略图图像;
CGContextSaveGState(上下文);
CGContextTranslateCm(上下文,0.0,aRect.size.height);
CGContextScaleCTM(上下文,1.0,-1.0);
CGContextSetGrayFillColor(上下文,1.0,1.0);
CGContextFillRect(上下文,aRect);
CGAffineTransform PDFTTransform=CGPDFPageGetDrawingTransform(第页,kCGPDFMediaBox,aRect,0,true);
CGContextConcatCTM(上下文,PDF转换);
CGContextDrawPDFPage(上下文,页面);
thumbnailImage=UIGraphicsGetImageFromCurrentImageContext();
[arrayOfImages addObject:thumbnailImage];
CGContextRestoreGState(上下文);
UIGraphicsSendImageContext();
CGPDF文件发布(pdf);
}
返回阵列图像;
}
使用此选项,可以提高质量。它以屏幕/设备的比例创建图像,iPhone 5系列为2.0,iPhone 6 plus为3.0
UIGraphicsBeginImageContextWithOptions(aRect.size,NO,[UIScreen mainScreen].scale)
下面默认使用比例因子1,这就是质量低的原因
UIGraphicsBeginImageContext(aRect.size)