[Pythonmac-SIG] Converting python for CoreGraphics

Jim Skibbie JSkibbie at schawk.com
Wed Jul 13 04:00:32 CEST 2011


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 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythonmac-sig/attachments/20110713/61d86d42/attachment.html>


More information about the Pythonmac-SIG mailing list