Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-05-2009, 05:05 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 30
Default Convert python code to iPhone

Hello,
I'm having a hard time getting my head wrapped around the CoreGraphics side of the house. So my first quick test was to convert this python script back to ObjC/CoreGraphics.

Code:
#!/usr/bin/python

from CoreGraphics import *
import sys
import os

if len (sys.argv) == 1:
    print "pdf2png file1.pdf [file2.pdf [...]]"
    sys.exit(1)

def dumpPNG(pdf, pageNumber, outFileBase):
    if pageNumber is None:
        outFile = outFileBase + ".png"
        pageNumber = 1
    else:
        outFile = outFileBase + "-%03d.png" % pageNumber

    w = pdf.getTrimBox(pageNumber).getWidth()
    h = pdf.getTrimBox(pageNumber).getHeight()

    ctx = CGBitmapContextCreateWithColor(int(w), int(h), CGColorSpaceCreateDeviceRGB(), (1,1,1,1))
    ctx.drawPDFDocument(pdf.getTrimBox(pageNumber), pdf, pageNumber)
    ctx.writeToFile(outFile, kCGImageFormatPNG)
    return outFile

for aFile in sys.argv[1:]:
    pdf = CGPDFDocumentCreateWithProvider(CGDataProviderCreateWithFilename(aFile))
    numberOfPages = pdf.getNumberOfPages()

    outFile = os.path.splitext(aFile)[0]

    if numberOfPages == 1:
        dumpPNG(pdf, None, outFile)
    else:
        for pageNumber in xrange(1, numberOfPages+1):
            writtenPath = dumpPNG(pdf, pageNumber, outFile)
            print "Wrote page #%d as %s" % (pageNumber, writtenPath)
The parts I'm having trouble with understanding is the "CGBitmapContextCreateWithColor". I dont see that API in the CoreGraphics framework.

Thanks,
tom
sunfire is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 158,307
Threads: 89,032
Posts: 379,815
Top Poster: BrianSlick (7,086)
Welcome to our newest member, percent17
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:48 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0