views:

21

answers:

2

CoreGraphics gives the possibility to render PDF documents, this is great. But it seems like it could support other types too like Word documents, HTML, RTF and others.

A quick look in the doc2pdf.py example on the Mac OS X Developer DVD makes me think so :

  pageRect = CGRectMake(0, 0, 612, 792)
  c = CGPDFContextCreateWithFilename(output_file, pageRect)
  c.beginPage(pageRect)

  if fnmatch(ext,".txt") or fnmatch(ext,".?") or fnmatch(ext,".??"):
    tr = c.drawPlainTextInRect(text, pageRect, font_size)
  elif fnmatch(ext,".rtf"):
    tr = c.drawRTFTextInRect(text, pageRect, font_size)
  elif fnmatch(ext,".htm*") or fnmatch(ext,".php"):
    tr = c.drawHTMLTextInRect(text, pageRect, font_size)
  elif fnmatch(ext,".doc"):
    tr = c.drawDocFormatTextInRect(text, pageRect, font_size)
  elif fnmatch(ext,"*ml"):
    tr = c.drawWordMLFormatTextInRect(text, pageRect, font_size)
  else:
    return "Error: unknown type '%s' for '%s'"%(ext, input_file)

Unfortunately, I do not understand how works the CoreGraphics' Python bindings (and it seems that the binding itself is binary and proprietary). I cannot find the C/Obj-C equivalent for these methods in Apple developers documentation. And there is not much webpages found by Google talking about these functionnality.

Any ideas ?

A: 

I don't think CoreGraphics alone does this. The App Kit Addition to the NSAttributedString class provides ways to initialize an attributed string from various kinds of documents, and to draw it in the current NSGraphicsContext.

JWWalker
A: 

I found how it works.

Here's a great Open-Source example here parsing doc, docx, odt, rtf, etc. files only by using Cocoa framework support for these formats : http://www.bean-osx.com/Bean.html

François Cassistat