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