I've been trying to make a program using a function to draw to a context that it is passed to render a custom view. I'd also like to be able to use the same function that draws into the window to draw into a PDF.

At the moment the drawing is done by importing Quartz, and drawing into the view's context using commands like

CGContextSetGrayFillColor(self.context,1.0,1.0)
CGContextFillRect(self.context,self.rect)

This works fine when I call it in my subclass of NSView, but when I try to draw into a PDF it doesnt work properly.

Looking at this page:
http://developer.apple.com/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_pdf/chapter_14_section_4.html#//apple_ref/doc/uid/TP30001066-CH214-CJBHHJCB

 I would have assumed that all you have to do is create a context for your PDF, and then I could draw into it as usual using my generic drawing function that renders the custom view.

However looking at the example file in /Developer/Examples/Quartz/Python/circle.py, they use CoreGraphics, and seem to be using a different calling style to call the drawing functions.

from CoreGraphics import *
import math   # for pi

pageRect = CGRectMake (0, 0, 612, 792)   #  landscape
c = CGPDFContextCreateWithFilename (" circle.pdf", pageRect)
c.beginPage (pageRect)
c.setRGBFillColor(1.0,0.0,0.0,1.0)
c.addArc(300,300,100,0,2*math.pi,1)
c.fillPath()
c.endPage()
c.finish()

I have tried using this, and inserting my code using 'c' as the context, but it does not work properly and gives the error:
2007-12-14 00:30:21.515 Python[992:613] <type ' exceptions.TypeError'>: depythonifying struct, got no sequence

I don't understand what the difference between using CoreGraphics and Quartz is, and why the calling conventions are different.

Do I need to use Quartz to create the PDF instead of CoreGraphics? Or do i need to rewrite my custom view using importing coregraphics instead of quartz? Why is the calling convention different? (the Quartz code I used for the custom view I took from the dotView example is similar to the function calls in the objective-C pdf creation example, whereas on the apple Quartz 2D python bindings page it is like the example above) 

Any help would be much appreciated!