调整PDF页面大小的问题

时间:2012-09-13 21:51:37

标签: ios pdf png

我需要将PDF文档的页面转换为单独的PNG文件,但是我在将大量PDF文档放入图形上下文时遇到了问题。无论我尝试哪种PDF,页面总是大约500像素高。如何获得每个页面的更大版本(/更高质量)?

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:[[_issue objectForKey:@"Issue"] lastPathComponent]];
NSURL *pdfFileUrl = [NSURL fileURLWithPath:pdfPath];
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((__bridge CFURLRef)pdfFileUrl);

CGPDFPageRef myPageRef = CGPDFDocumentGetPage(pdf, pageNumber);
CGRect aRect = CGPDFPageGetBoxRect(myPageRef, kCGPDFCropBox);
UIGraphicsBeginImageContext(CGSizeMake(2008 / (aRect.size.height / aRect.size.width), 2008));
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextTranslateCTM(context, 0.0, aRect.size.height);
CGContextScaleCTM(context, 2.0, -1.0);

CGContextSetGrayFillColor(context, 1.0, 1.0);
CGContextFillRect(context, aRect);

CGPDFPageRef page = CGPDFDocumentGetPage(pdf, pageNumber);
CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFMediaBox, aRect, 0, true);

CGContextConcatCTM(context, pdfTransform);
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextSetRenderingIntent(context, kCGRenderingIntentDefault);
CGContextDrawPDFPage(context, page);

1 个答案:

答案 0 :(得分:0)

正如iPDFdev在评论中回答的那样,可以在此处找到解决方案:Best way to convert PDF to high-resolution image in Cocoa