 |
 |
|
 |
07-05-2009, 05:05 PM
|
#1 (permalink)
|
|
Registered Member
Join Date: Feb 2009
Posts: 27
|
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
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 484 |
| 62 members and 422 guests |
| activ8, Alexman, amiralic, amoll, angelFrog, bbc z, BillHerr79, bluemonkey, brianmethod, BrianSlick, Chonch, Corsu, CoxTral, craig.w, danbaumbach, dany88, dda, digidan, dre, Drudoo, eemceebee, eJohnny, Erle, fede, gjosef, healthyutech, imsatasia, Jeremy1026, JJGEight, johny_abo, KenPletzer, krisix, lanej, linuxgood, lws, MacSteve85, markbuchanan, mlfarrell, mlo, Mopedhead, Mr Jack, MrMattMac, nicholask, nonamelive, Nungster, P2k, pokypine, QAD, raees, redmouse, ryguy2503, scotopia, staticouture, TheAppByte, TheGiant, themathminister, tomoan74, Tuszy, xyster, zivido, ZunePod |
| Most users ever online was 779, 05-11-2009 at 10:55 AM. |
» Stats |
Members: 21,499
Threads: 35,780
Posts: 156,754
Top Poster: smasher (2,448)
|
| Welcome to our newest member, staticouture |
|