gpt4 book ai didi

ios - 在iOS上生成高分辨率pdf

转载 作者:行者123 更新时间:2023-12-01 16:51:36 24 4
gpt4 key购买 nike

有什么方法可以在支持视网膜显示的ios上生成高分辨率PDF?我做了一个基本的PDF生成器,但在我的iPad 3上,它仍然看起来像是像素化的。谢谢您的各种建议!

更新:

在我的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上下文并在其中原生绘制即可。现在,以全分辨率绘制字体时,字体将显得清晰,而不是一半rez,然后放大该字体的位图,这当然会造成锯齿。

tl; dr:直接绘制到pdf,请勿对文本使用缩放变换。

关于ios - 在iOS上生成高分辨率pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15282811/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com