using Mac OS X CoreGraphics via ctypes

Diez B. Roggisch deets at nospam.web.de
Fri Jun 15 08:00:16 CEST 2007


Daniel schrieb:
> I'm trying to implement a routine that converts a PDF document to
> image files using ctypes and the Apple CoreGraphics library as per the
> 'Splitting a PDF File' example on Apple's web site [0]. Unfortunately
> I cannot use the CoreGraphics module used in that example because I'm
> using Python 2.5 (AFAIK that module is only available in the system
> default Python 2.3.5). There are three questions in the code snippet
> below. Each problem area has been commented out in the example so it
> runs through to the end. The code is obviously not complete, but it's
> enough do demonstrate my problems so far.
> 
> BTW, this is the only way I have found to convert a PDF (generated by
> ReportLab) to an image that can be fed into a PyQt (v3) QPrinter
> object. If anyone knows another way to gain access to the system print
> services on Mac OS X using Python please do tell. Oh yes, I'd rather
> not include PyObjC because I'm already packaging PyQt, and that would
> make the resulting app a lot bigger.

> # BEGIN CODE
> from ctypes import cdll, c_void_p
> from ctypes.util import find_library
> 
> cglib = cdll.LoadLibrary(find_library('ApplicationServices'))
> 
> # the next line causes a segfault - what's the right way to do this?
> #GCS_RGB = cglib.kCGColorSpaceGenericRGB()

Usually, things in the OSX lib that start with k* are a constant - not a 
function. As is this.


Diez



More information about the Python-list mailing list