title: Display thumbnails for pdf files in iphone
body: <p>Hello I'm developing an application which displays a pdf file in <code>UIWebView</code>. I want to display the thumbnails of all the pages of pdf files it contains where the user can select his own page he is interested in. I found one sample code to get thumbnails but I'm unable to display it.</p>
  
  <pre><code>UIWebView* webView = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  webView.backgroundColor = [UIColor whiteColor];
  
  NSString *fileName= @"2_slo_sample";
  NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"pdf"];
  NSURL* pdfFileUrl = [NSURL fileURLWithPath:path];
  NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:path isDirectory:NO]];
  [webView setScalesPageToFit:YES];
  [webView loadRequest:request];
  webView.scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, 480);
  webView.scrollView.alwaysBounceHorizontal = YES;
  
  [self.view addSubview:webView];
  
  CGPDFPageRef page;
  CGRect aRect = CGRectMake(0, 0, 70, 100); // thumbnail size
  UIGraphicsBeginImageContext(aRect.size);
  
  CGContextRef context = UIGraphicsGetCurrentContext();
  CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((__bridge CFURLRef)pdfFileUrl);
  NSUInteger totalNum = CGPDFDocumentGetNumberOfPages(pdf);
  
  for(int i = 0; i &lt; totalNum; i++ ) {
      CGContextSaveGState(context);
      CGContextTranslateCTM(context, 0.0, aRect.size.height);
      CGContextScaleCTM(context, 1.0, -1.0);
  
      CGContextSetGrayFillColor(context, 1.0, 1.0);
      CGContextFillRect(context, aRect);
  
      // Grab the first PDF page
      page = CGPDFDocumentGetPage(pdf, i + 1);
      CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, aRect, 0, false);
      // And apply the transform.
      CGContextConcatCTM(context, pdfTransform);
  
      CGContextDrawPDFPage(context, page);
  
      // Create the new UIImage from the context
      thumbnailImage = UIGraphicsGetImageFromCurrentImageContext();
  
      CGContextRestoreGState(context);
  }
  
  UIGraphicsEndImageContext();
  CGPDFDocumentRelease(pdf);
  </code></pre>
  
  <p>I'm sure I'm masking some mistake in it. Could you please tell me where I need to get corrected?</p>