On 13 Jul, 2011, at 4:00, Jim Skibbie wrote:
> I have a python script that takes a PDF file and returns the width and height of the document's first page. When I moved this to Snow Leopard, I have to run this in 32-bit mode or I can an error:
> File "/BinaryCache/CoreGraphicsBindings/CoreGraphicsBindings-26~139/Root/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/CoreGraphics/__init__.py", line 7, in <module>
> ImportError: /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/CoreGraphics/_CoreGraphics.so: no appropriate 64-bit architecture
> Googling around, I find that CoreGraphics is no longer bound to python in Snow Leopard and that it will eventually need to be converted to PyObjC.
> Can anyone point me in a direction on where I might find some information on how to do this kind of porting?
The Quartz APIs are available through pyobjc (using "import Quartz"). IIIRC the CoreGraphics module contains an OO-ish interface, the Quartz module is just a straightforward mapping of the C API, which means you have to call global functions instead of methods on objects.
One thing you will probably run into is functions that aren't avaiable in the Quartz package: the CoreGraphics module contains a number of functions that aren't wrappers for functions in the public C API of the CoreGraphics framework, and those functions are therefore not available in the Quartz .
Ronald
> The existing script is below:
> # step 1: import the required modules
> import os, sys
> from CoreGraphics import *
>> if len( sys.argv ) != 2:
> print "ERROR: useage: python example2.py pdf_filename"
> sys.exit(1)
>> # step 2: read the pdf file name from the command line arguments
> pdf_filename = sys.argv[1]
> pdf_name, ext = os.path.splitext( pdf_filename )
>> # step 3: create the input PDF document
> provider = CGDataProviderCreateWithFilename( pdf_filename )
> pdf = CGPDFDocumentCreateWithProvider( provider )
> if pdf is None:
> print "ERROR reading PDF document - \r\n check that the supplied filename points to a PDF file"
> sys.exit(1)
>> page_number = 1
>> #page_rect = pdf.getMediaBox( page_number )
>> page_rect = pdf.getPage(page_number).getBoxRect(page_number)
>> page_width = float(page_rect.getWidth())
> page_height = float(page_rect.getHeight())
>> print "%f\r\n%f" % (page_width, page_height)
>> Thanks.
> Jim
> _______________________________________________
> Pythonmac-SIG maillist - Pythonmac-SIG at python.org>http://mail.python.org/mailman/listinfo/pythonmac-sig> unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythonmac-sig/attachments/20110715/31aceba0/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2224 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/pythonmac-sig/attachments/20110715/31aceba0/attachment.bin>