views:

1199

answers:

1

While I was going thru the pdf document in quartz 2D, they were saying about getting a page from the CGPDFDocument object. Then the draw the page in a CGContextRef object.

CGPDFDocumentRef document = MyGetPDFDocumentRef (filename);
CGPDFPageRef page = CGPDFDocumentGetPage (document, pageNumber); 
CGContextDrawPDFPage (myContext, page); 
CGPDFDocumentRelease (document); 

Everything is done into this context. I dont understand how these things done to a context can be viewed in a view OR Am i missing something? I am viewing the pdf in a webView.

+2  A: 

A CGContextRef is a canvas for drawing 2D stuff on it. The code you quoted draws a PDF page on the canvas.

Every UIView has a -drawRect: method for rendering the view on screen. In the method a CGContextRef is automatically provided (UIGraphicsGetCurrentContext()) for you to draw what you needed.

KennyTM
So it means that if I write the drawRect method in a viewController.m and do some actions in the context(which I will get using the UIGraphicsGetCurrentContext), then it will be reflected in the view, isn't it?
wolverine
@wolverine: Yes.
KennyTM
And when is this drawRect method called? Just before the screen is going to load OR can we make it call whenever we desire?
wolverine
@wolverine: If you need to invoke it manually, call `[view setNeedsDisplay];`.
KennyTM
Your drawRect: method needs to be in the view, not the viewController, correct? Which means you'll need to subclass the view to make this work.
Greg Maletic