rentzsch.com: tales from the red shed

Cocoa as a PDF API

Mac OS X
This Associated Press article by Anick Jesdanun ("PRODUCT REVIEW: PDF Alternatives Emerge") doesn't paint a pretty picture about Mac OS X:
The Mac OS X operating system comes with a rudimentary PDF-creation program, but comparing it with Adobe's is like pitting Little Leaguers against the Boston Red Sox.

I'll begin by conceding Mac OS X's PDF output abilities don't mesh well with Anick's criteria. Things like hyperlinks are lost if you try to output a PDF from Safari. In addition, Mac OS X also tends to bloat PDF output. Usually it's not unacceptably bad, but it definitely doesn't match Acrobat. Finally Mac OS X can't natively create PDF forms.

That said, I have a number of issues with this article. First, the headline is hopelessly misleading. One headline that would match the body would be "PRODUCT REVIEW: PDF Generator Alternatives Emerge". Another would be "PRODUCT REVIEW: Acrobat Alternatives Emerge". You see, the article in question doesn't call into question the PDF file format itself. Instead, the article does as far as to reinforce the notion that PDF is king for ePaper formats (which I largely agree with). Really, the article is all about alternatives to Acrobat, not alternatives to PDF itself.

My second issue is with the notion Mac OS X includes "a rudimentary PDF-creation program". This is completely incorrect. Instead, at a fundamental level, Mac OS X can persist low-level drawing actions (CoreGraphics aka Quartz 2D) into PDF file format.

So Mac OS X does not ship with a "a rudimentary PDF-creation program" at all. That's unless you consider an arbitrary app printing-to-PDF a "PDF-creation program". In which case, Anick is still incorrect: there's multiple apps that ships with Mac OS X that can generate PDF, from the lowly TextEdit to iPhoto, including somewhat ironically Acrobat Reader itself.

But I don't intend to make the article's inaccuracies my main point here. Instead, I'd like to point out something that just occurred to me two weeks ago: Cocoa may be the world's best PDF API.

Case in point, I was able to use Interface Builder as a simple template layout system. That, coupled with 66 lines of ObjC code, read in, flowed, paginated and spat out Dostoevsky's Crime and Punishment in PDF form with a custom "page" size (7" x 10"). The code took 8 seconds to process the 300+ page book on a 800 MHz TiBook G4.

Cocoa's text layout system makes it relatively straight-forward to define multiple text boxes -- perhaps one per page or per column -- and flow huge text streams into it. Dumping it all to PDF becomes a simple matter of handing one big NSView to NSPrintOperation with some extra information (PDF file output path, page size, etc).

Bottom line: Mac OS X plus Cocoa allows you to quickly and easily output PDF files, be they one-pager info sheets or entire books. That's quite a span of ability, and it seems rather unknown.

Sunday, October 12, 2003
01:15 AM