如何以更高分辨率将 PDF 绘制到 CGContext?
我编写了一个视图来渲染 PDF 页面:
-(UIPDFRenderView*) initWithFrame:(CGRect)frame withDocument:(CGPDFDocumentRef*)document withPageNumber:(int)pageNumber
{
if (self)
{
page = CGPDFDocumentGetPage (*document, pageNumber);
pageRect = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
pdfScale = (CGRectGetWidth(frame)/pageRect.size.width);
rect = frame;
self = [super initWithFrame:CGRectMake(CGRectGetMinX(frame),
CGRectGetMinY(frame),
CGRectGetWidth(frame),
CGRectGetHeight(pageRect) * pdfScale)];
}
return self;
}
-(void) drawRect:(CGRect)rect
{
[self displayPDFPageWithContext:UIGraphicsGetCurrentContext()];
}
-(void) displayPDFPageWithContext:(CGContextRef)context
{
CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0);
CGContextFillRect(context, self.bounds);
CGContextSaveGState(context);
CGContextTranslateCTM(context, 0.0, self.bounds.size.height);
CGContextScaleCTM(context, pdfScale,-1*pdfScale);
CGContextDrawPDFPage (context, page);
}
我对 pdf 文档的每一页使用该视图之一,并将它们添加到 acrollview 中。 问题是如果我放大,页面是像素化的。毫不奇怪,因为我正在使用屏幕上下文来渲染 pdf。是否有可能以双倍分辨率渲染该 pdf,以便放大至 2 倍?
I wrote a view to render a PDF Page:
-(UIPDFRenderView*) initWithFrame:(CGRect)frame withDocument:(CGPDFDocumentRef*)document withPageNumber:(int)pageNumber
{
if (self)
{
page = CGPDFDocumentGetPage (*document, pageNumber);
pageRect = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
pdfScale = (CGRectGetWidth(frame)/pageRect.size.width);
rect = frame;
self = [super initWithFrame:CGRectMake(CGRectGetMinX(frame),
CGRectGetMinY(frame),
CGRectGetWidth(frame),
CGRectGetHeight(pageRect) * pdfScale)];
}
return self;
}
-(void) drawRect:(CGRect)rect
{
[self displayPDFPageWithContext:UIGraphicsGetCurrentContext()];
}
-(void) displayPDFPageWithContext:(CGContextRef)context
{
CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0);
CGContextFillRect(context, self.bounds);
CGContextSaveGState(context);
CGContextTranslateCTM(context, 0.0, self.bounds.size.height);
CGContextScaleCTM(context, pdfScale,-1*pdfScale);
CGContextDrawPDFPage (context, page);
}
I use one of that view for every page of a pdf document and add them to a acrollview.
The problem is if i zoom in, the page is pixelig. No surprise because i am using the screen context to render the pdf. Is there any posibility to render that pdf with the double resolution to enable zoomin to a factor of 2?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我得到了解决方案,我以原始大小渲染它,并以低比例启动 scollview,使 pdf 的宽度适合滚动视图的宽度。使用该方法我可以缩放到原始大小(比例为1)。
Okay i got the solution, i render it in original size and initiate the scollview with a low scale that the width of the pdf fits with the width of the scrollview. With that methode i can zoom till original size (scale of 1).