Edit AllPages

I’m writing a Cocoa class to manage newspaper ads and would like to provide a method to generate very simple placeholder TIFFs for ads that have not been completed yet. The tiffs aren’t for display in my app (they’ll be imported into Quark picture boxes), so they don’t need a window or view during creation.

I read the NSGraphicsContext documentation along with the NSBezierPath but can’t figure out how to set up a context and draw to it.

The NSGraphicsContext documentation says that it accepts NSData objects as drawing targets but I keep getting “Unsupported printing format specified” and “Currently only pathnames are allowd for NSPersistentGraphicsContext” in my attempts.

Basically here’s what I’m trying to do:

And here’s the create placeholder method so far (such as it):

Thanks for any help,


I think you’re being over-complicated. You can draw into NSImage, so simply create a new NSImage, lockFocus on it, draw, unlockFocus, and ask it for some TIFF data.

I wasn’t aware that you could draw text to an NSImage. How would you go about that?

The same way you’d draw text into a view. Lock focus on the image (this is normally done for you with a view), draw the text using NSString or NSAttributedString methods, unlock focus. Once you’ve done lockFocus on the image, all drawing can be done normally.

also, that path is wrong. remove ‘System (OS X)’ and it will be correct. –boredzo

And instead of relying on the current user being kentozier… [@”~/Desktop/bobo.pdf” stringByExpandingTildeInPath]

Here’s an example of drawing into an image:

// To actually save the tiff file out …