Python CoreGraphics script running in Applescript
Python CoreGraphics script running in Applescript
- Subject: Python CoreGraphics script running in Applescript
- From: Jim Skibbie <email@hidden>
- Date: Fri, 30 Jan 2009 13:47:50 -0600
- Thread-topic: Python CoreGraphics script running in Applescript
Title: Python CoreGraphics script running in Applescript
I have a script that needs to get the height and width dimensions of the media box of a PDF using Applescript. In OS X 10.4, I was using the following:
set shellScript to "python " & quoted form of PythonPath & " " & POSIXThisFile
set dims to every paragraph of (do shell script shellScript)
The PythonPath is a path to the below Python script and the POSIXThisFile is the path to the PDF.
The response is two paragraphs where paragraph 1 is the width and paragraph 2 is the height.
Here’s the python script:
# 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_width = int(page_rect.getWidth())
page_height = int(page_rect.getHeight())
print "%d \r\n%d" % (page_width, page_height)
Under OS 10.5, this script now uses a deprecated function of CoreGraphics and I get an error that says:
<Error>: The function `CGPDFDocumentGetMediaBox' is obsolete and will be removed in an upcoming update. Unfortunately, this application, or a library it uses, is using this obsolete function, and is thereby contributing to an overall degradation of system performance. Please use `CGPDFPageGetBoxRect' instead.
Can anyone steer me in the right direction on how to work with the CGPDFPageGetBoxRect function?
Thanks.
Jim
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden