When I began this project, I was in a low point for my day job: the clients were unusually quiet, and I was even starting to get that pain-in-the-gut feeling when things are going bad. Right now, of course, things are right back to normal: crazy clients with crazy websites and crazy deadlines. So I’ve been working my fanny off, and subsequently paying less attention to our dear Napkin. But it’s still very much on my mind, and after a couple weeks, I’m back. A couple jobs have ended and I can give this some attention. And I’ve realized that when I last wrote, I was going to deal with printing! Well, I actually did that in the last two weeks, and forgot to write about it. Bad nerd!

So here’s the big payoff: printing is pretty easy to implement in a basic way, but becomes a total bear when you want tight control. At the risk of looking like a Windows developer, I opted for now to get the basics working, then coming back to make it work right.

Hillegass has a good chapter on printing (although any chapter that begins “Code to handle printing is always relatively hard to write” just sent shivers up my spine), and he lays it out very well: your NSDocument class implements a simple method call, and you supply the view that will be printed. In the case of a text document, it’s not too hard, because your view is a TextView, which is basically just a blob of text:

– (NSPrintOperation *)printOperationWithSettings:(NSDictionary *)ps error:(NSError **)e { NSPrintInfo *printInfo = [self printInfo]; NSPrintOperation *printOp = [NSPrintOperation printOperationWithView:textView printInfo:printInfo]; return printOp; }

So you just hand over the textView to the NSPrintOperation method, and it takes care of the rest.


No, nothing’s ever easy, is it? Check that — undo and copy/paste was easy. But in this case, when I print a Napkin document, something a tad funky happens.

Christ, I mean TWO somethings happen. Because just as I was going to produce a screenshot of my problem, I discovered another one. In a nut:

  1. The right margin is a tad too friendly with the left; and
  2. The top margin is a tad too arbitrary, preferring to centre content on the page.

Here’s where a stylin’ photograph comes in handy. Click it to see the full image.


See, before I started writing this blog post, I was content to deal with the issues of the top margin. I mean, it’s unsexy, but still — technically — functional. Now, of course, the right margin is obviously a big problem, and makes my printing capability a total no-go. Crap. Crap crap crap.

Okay, I’m taking some deep breaths now. Because, if you really want to make printing your bitch, you have to do what to me right now represents an unthinkable task: creating a special view, just for printing! A scary view that is positioned on a hypothetical, arbitrarily-sized piece of paper, or worse, multiple sheets of said paper. You at least have to account for that!

So that’s just derailed my day. Because as I set out on this post, I was looking to just put the printing thing behind me and get to something else I’ve been working on. But no, that’s not how we roll here. I’m going to return to Hillegass, and I’m going to create that view, and I’m not only going to make printing work, I’m going to make it work right, and it’s going to be awesome.

But it probably won’t be today.