6

In my app I have a method that draws a pdf into a context:

 CGPDFPageRef page = CGPDFDocumentGetPage(pdf, index + 1);

 CGAffineTransform transform = aspectFit(CGPDFPageGetBoxRect(page, kCGPDFTrimBox),
                                                          CGContextGetClipBoundingBox(ctx));

 CGContextConcatCTM(ctx, transform);

 CGContextDrawPDFPage(ctx, page);

Now in drawLayer, that is called when zooming, I do the necessary transformations and call again CGContextDrawPDFPage(ctx, page);

What happens is that a zoomed pdf is drawn on top of the first pdf, the problem is that in a particular page with only text, the back and blurred pdf is shown. That is strange, I thought that pdf page had white background and if this happens it's because the zoomed pdf on top has transparent background.

Now, to solve this how can I clear the context right before the CGContextDrawPDFPage(ctx, page) of drawLayer method? I tried:

//self.view.transform = CGAffineTransformIdentity;

//CGAffineTransform transform = CGAffineTransformIdentity;
//CGContextConcatCTM(ctx, transform);

//CGContextClearRect(ctx, layer.bounds);

Nothing works...thanks in advance

Vin
  • 10,517
  • 10
  • 58
  • 71
lopes710
  • 315
  • 1
  • 3
  • 19
  • Your question suggests that the first context is not the same context as you use in `drawLayer:`. How do you create the original ctx, when do you draw into it, and what are you doing with it afterwards? – Rob Napier Mar 15 '12 at 16:42

2 Answers2

13
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, self.bounds);
Will
  • 1,573
  • 14
  • 13
4

Did you try to flush the context as below?

CGContextFlush(ctx);
cocoakomali
  • 1,346
  • 1
  • 8
  • 7