2
有什么方法可以在支持视网膜显示的ios上生成高分辨率PDF?我制作了一个基本的PDF生成器,但在我的iPad 3上它仍然看起来像素化。感谢您提供各种建议!在ios上生成高分辨率pdf
更新:
在我的PDF文件中的文本是光滑美观。但是当我使用代码来绘制这个pdf时,我在视网膜显示上得到了像素化(绘图代码在底部)。
PDF生成:
NSString *fileName = [self.bookManager cacheBookFileForPage:i];
UIGraphicsBeginPDFContextToFile(fileName, CGRectZero, nil);
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextSetTextMatrix(currentContext, CGAffineTransformIdentity);
CGContextTranslateCTM(currentContext, 0, 100);
CGContextScaleCTM(currentContext, 1.0, -1.0);
// TODO: Temporary numbers
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 768 * 2, 1024 * 2), nil);
NSString *textToDraw = @"text";
CFStringRef stringRef = (__bridge CFStringRef)textToDraw;
CTFontRef ctFont= CTFontCreateWithName(CFSTR("Arial"), 20 * 2, &CGAffineTransformIdentity);
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
(__bridge id)ctFont, (NSString *)kCTFontAttributeName,
nil];
NSAttributedString *string = [[NSAttributedString alloc] initWithString:textToDraw
attributes:attributes];
CFRelease(ctFont);
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)string);
// TODO: temporary
CGRect frameRect = CGRectMake(100, 100, 800 * 2, 50 * 2);
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);
// Draw the frame.
CTFrameDraw(frameRef, currentContext);
CFRelease(frameRef);
CFRelease(stringRef);
CFRelease(framesetter);
// Close the PDF context and write the contents out.
UIGraphicsEndPDFContext();
PDF图纸:
// This will return pageRef from PDF
CGPDFPageRef page = [self.bookManager contentForPage:index + 1];
CGContextSetRGBFillColor(context, 1.0f, 1.0f, 1.0f, 1.0f);
CGContextFillRect(context, CGContextGetClipBoundingBox(context));
CGContextTranslateCTM(context, 0.0f, [self.view.layer bounds].size.height);
CGRect transformRect = CGRectMake(0, 0, [self.view.layer bounds].size.width, [self.view.layer bounds].size.height);
CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, transformRect, 0, true);
// And apply the transform.
CGContextConcatCTM(context, pdfTransform);
CGContextScaleCTM(context, 1.0f, -1.0f);
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextSetRenderingIntent(context, kCGRenderingIntentDefault);
CGContextDrawPDFPage(context, page);
你在文档中有什么样的内容?如果你的图像包含锯齿,那么你需要提高他们的分辨率。如果你的字体是像素化的,那么你可能没有使用基于矢量的字体 - 你使用的是什么字体?你是如何生成PDF的? – halfer 2013-03-07 23:35:58
@halfer你是对的。这个问题需要一些代码:) – 2013-03-07 23:56:22
一个更好的问题。好的,如果您在桌面计算机上查看生成的PDF,是否以高缩放级别显示锯齿形字体?如果没有,那么问题出现在您的显示代码中。 (不是iOS程序员,但现在你的问题中有代码,有人可以帮助你)。 – halfer 2013-03-08 00:01:03