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?
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).
精彩评论