Printing with WebKit

I’ve been working on the printing code for Hamilton 1.1 and found it easiest to use WebKit to get the job done. I initially thought it was going to be a little tricky, but it turned out to be pretty easy.

I created a little demo app to show how it’s done. The demo app simply loads a URL into a WebView instance that I setup in Interface Builder, the AppController class I wrote handles all the printing work. In Hamilton the WebView isn’t even visible, and I generate the HTML to be printed on the fly as a way to generate simple reports. You could probably even do something more interesting using XSL or by pulling content from a database.

Download the Xcode project: WebKitPrinting.zip (36kb)

A screenshot of my WebKitPrinting demo in action:

webkitprinting.jpg

Got comments or ideas for how to improve this? Please, let me know!

Leave a Reply