title: Rendering PDF document having 200 pages on iPad
body: <p>I have to develop an application which takes PDF as input, that PDF document has 200 pages. I am using UIScrollView to swipe left and right. On each swipe I am drawing a PDF document. The code is as under :</p>
  
  <pre><code>- (id)initWithFrame:(CGRect)frame content:(NSString *)aPDFPage type:(NSString *)contentType
  {
      if ((self = [super initWithFrame:frame])) 
      {
          // Initialization code
          self.backgroundColor = [UIColor whiteColor];
          pageRef = [[NSString alloc]initWithString:aPDFPage];
          pageTypeRef = [[NSString alloc]initWithString:contentType];
      }
      return self;
  }
  
  
  - (void)drawRect:(CGRect)rect 
  {
      ctx = UIGraphicsGetCurrentContext();
      [self drawPDF];
  }
  
  -(void)drawPDF
  {
      NSString *pathToPdfDoc = [[NSBundle mainBundle] pathForResource:self.pageRef ofType:self.pageTypeRef];
      NSURL *pdfUrl = [NSURL fileURLWithPath:pathToPdfDoc];
  
      document = CGPDFDocumentCreateWithURL((CFURLRef)pdfUrl);
  
      page = CGPDFDocumentGetPage(document, 1);
      CGContextTranslateCTM(ctx, 0.0, [self bounds].size.height);
      CGContextScaleCTM(ctx, 1.0, -1.0);
  
      CGAffineTransform transform = aspectFit(CGPDFPageGetBoxRect(page, kCGPDFTrimBox),CGContextGetClipBoundingBox(ctx));
  
      CGContextConcatCTM(ctx, transform);
  
      CGContextSetInterpolationQuality(ctx, kCGInterpolationLow); 
      CGContextSetRenderingIntent(ctx, kCGRenderingIntentDefault);
  
      CGContextDrawPDFPage(ctx, page);
      CGPDFDocumentRelease(document);
  }
  
  
  -(void)dealloc 
  {
      [pageRef release];
      [pageTypeRef release];
      [super dealloc];
  }
  </code></pre>
  
  <p>This works fine. But if I swipe very fast, more often subsequent pages does not load instantly. Screen becomes white.</p>
  
  <p>How to solve this, please guide.</p>
  
  <p>Regards,
  Ranjan</p>