| OS X - Development and Darwin Discussion and questions about development for Mac OS X. |
| Post Reply | New Thread | Subscribe |
|
|
Thread Tools |
![]() Member Since: Dec 10, 2009
Posts: 1
![]() |
Does anyone have an example of using the PyObjC bridge to use the CoreGraphics and Quartz libraries in Snow Leopard.
I want to use the example but am not sure how to get it working. I know I have to import objc but do not know what else is required to get it working. Would appreciate any assistance. Mike # step 1: import the required modules import os, sys from CoreGraphics import * if len( sys.argv ) != 2: print "usage: 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 ) # NOTE: on Panther use cs = CGColorSpaceCreateDeviceRGB() cs = CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB ) # step 3: create the input PDF document provider = CGDataProviderCreateWithFilename( pdf_filename ) pdf = CGPDFDocumentCreateWithProvider( provider ) if pdf is None: print "Error reading PDF document - check that the supplied filename points to a PDF file" sys.exit(1) # page number index is 1-based for page_number in range( 1, pdf.getNumberOfPages() + 1 ): page_rect = pdf.getMediaBox( page_number ) page_width = int(page_rect.getWidth()) page_height = int(page_rect.getHeight()) # step 4: create an appropriate bitmap and draw the PDF bitmap = CGBitmapContextCreateWithColor( page_width, page_height, cs, (1,1,1,1) ) bitmap.drawPDFDocument( page_rect, pdf, page_number ) # step 5: write out the bitmap to a PNG file (and log each file) page_filename = "%s_%d.png" % (pdf_name, page_number) print "Writing image: %s, width x height: (%d x %d)" \ % (page_filename, page_width, page_height) bitmap.writeToFile( page_filename, kCGImageFormatPNG ) |
| QUOTE Thanks | |
| Post Reply | New Thread | Subscribe |
| Thread Tools | |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|
|||||||
Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| can I update this to snow lepoard? | bgardner15 | OS X - Operating System | 2 | 12-07-2009 12:21 PM |
| Snow lepoard running crazy slow | BostonMarley | OS X - Operating System | 46 | 10-18-2009 01:25 PM |
| Snow Lepoard drawbacks | elwitz | OS X - Operating System | 4 | 08-27-2009 05:34 PM |
| Client-side cookies on Python in Mac OSX | Hikaru79 | OS X - Development and Darwin | 0 | 07-12-2007 10:25 PM |
All times are GMT -4. The time now is 02:05 PM.
Powered by vBulletin