Reputation: 101
i have created thumbnails for pdf file.so whenever the user clicks any one of the thumbnail it should be displayed in full screen.so i have used UIImageView to dispaly it.the prob is that.instead of displaying
but it is displaying like this which is not clear....
the code which i am using to display is
(void) displayPdf
{
CGFloat width = 60.0;
NSLog(@"%d",i);
//UIImage* thumbnailImage;
NSLog(@"%@",fileName);
// NSString*fileName= @"2_slo_sample";
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"pdf"];
NSURL* pdfFileUrl = [NSURL fileURLWithPath:path];
CGPDFPageRef page;
CGRect pageRect = CGRectMake(0, 0, 150,150);
CGFloat pdfScale = width/pageRect.size.width;
pageRect.size = CGSizeMake(pageRect.size.width*pdfScale, pageRect.size.height*pdfScale);
pageRect.origin = CGPointZero;
UIGraphicsBeginImageContext(pageRect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((__bridge CFURLRef)pdfFileUrl);
//NSUInteger totalNum = CGPDFDocumentGetNumberOfPages(pdf);
CGContextSaveGState(context);
CGContextTranslateCTM(context, 0.0, pageRect.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextSetGrayFillColor(context, 1.0, 1.0);
CGContextFillRect(context, pageRect);
// Grab the first PDF page
page = CGPDFDocumentGetPage(pdf, i);
CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, pageRect, 0, false);
// And apply the transform.
CGContextConcatCTM(context, CGPDFPageGetDrawingTransform(page, kCGPDFMediaBox, pageRect, 0, true));
CGContextDrawPDFPage(context, page);
// Create the new UIImage from the context
thumbnailImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGPDFDocumentRelease(pdf);
//webView.hidden = YES;
imageView1 = [[UIImageView alloc] init];
imageView1.frame =CGRectMake(0, 50, 280, 280);
[imageView1 setContentMode:UIViewContentModeScaleAspectFit];
[imageView1 setNeedsDisplay];
imageView1.backgroundColor = [UIColor clearColor];
[imageView1 setUserInteractionEnabled:YES];
imageView1.image = thumbnailImage;
[self.view addSubview:imageView1];
}
so kindly please help me so that i can display it clearly.
thanks in advance
Upvotes: 0
Views: 211
Reputation: 6211
You are creating an imageview out of a pdf page. That is all fine and dandy, but I presume you are creating this image in the small thumbnail size and then, when you desire, you resize that image to full screen. That's like the common CSI misthought (enhance, enhance, enhance...). Since you created the imageview with a limited size you cannot just increase it's size and expect pixel clarity to automatically appear.
You have a couple different options:
You can make your thumbnails the full page size and then shrink them down to thumbnail size (that will take a lot of memory, possibly too much depending on how big your pdf is).
You can recreate the imageview's image when it's size changes (that would take a lot of processing power and possibly bog down the UI, causing irritation).
Or you can draw the pdf in a custom UIView's drawRect:
function. This one is the most common (from what I have read). then when you change the UIView's size to make it full screen all you have to do is tell it to setNeedsDisplay
. For a really good code example of this option I suggest you look at PDFKitten. It is likely much much more in depth than you are looking for, but it helped me quite a bit.
Upvotes: 1