ページの中央に画像があるPDFをレンダリングする次のコードがあります。ただし、画像 (および実際のテキスト) は非常にピクセル化されており、明らかに Retina ディスプレイ用に設計されていません。
次のコードで何をしていないのですか?
-(void)drawText
{
NSString* fileName = @"Workbook.PDF";
NSArray *arrayPaths =
NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory,
NSUserDomainMask,
YES);
NSString *path = [arrayPaths objectAtIndex:0];
NSString* pdfFileName = [path stringByAppendingPathComponent:fileName];
// Create the PDF context using the default page size of 612 x 792.
UIGraphicsBeginPDFContextToFile(pdfFileName, CGRectZero, nil);
CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), YES);
for(UIImage *image in _pages)
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString* textToDraw = [NSString stringWithFormat:@"Page %i of %@", [_pages indexOfObject:image] + 1, [defaults objectForKey:@"OpenBookKey"]];
CFStringRef stringRef = (__bridge CFStringRef)textToDraw;
// Prepare the text using a Core Text Framesetter.
CFAttributedStringRef currentText = CFAttributedStringCreate(NULL, stringRef, NULL);
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(currentText);
CGRect frameRect = CGRectMake(230, 0, 612, 50);
CGMutablePathRef framePath = CGPathCreateMutable();
CGPathAddRect(framePath, NULL, frameRect);
// Get the frame that will do the rendering.
CFRange currentRange = CFRangeMake(0, 0);
CTFrameRef frameRef = CTFramesetterCreateFrame(framesetter, currentRange, framePath, NULL);
CGPathRelease(framePath);
// Mark the beginning of a new page.
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 792), nil);
// Get the graphics context.
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGRect frame = CGRectMake(20, 50, 550, 550);
[image drawInRect:frame];
CGContextSetTextMatrix(currentContext, CGAffineTransformIdentity);
CGContextTranslateCTM(currentContext, 0, 100);
CGContextScaleCTM(currentContext, 1.0, -1.0);
// Draw the frame.
CTFrameDraw(frameRef, currentContext);
CFRelease(frameRef);
CFRelease(stringRef);
CFRelease(framesetter);
}
// Close the PDF context and write the contents out.
UIGraphicsEndPDFContext();
}