0

我需要将 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);
4

1 回答 1

0

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

于 2012-10-23T09:26:17.790 回答