| Main |

NSImage and PDF

One thing that seems to annoy people about NSImage is the fact that although you can get TIFF data by using the -TIFFRepresentation method, there is no obvious way to turn one directly into a PDF. This seems like an odd omission when you consider that Quartz directly supports PDF… anyway, I thought I'd rectify the situation by posting some code that implements a -PDFRepresentation method.

Anyway, here's the code, for those that want to have a look. By the way, I'd be interested to hear any comments anyone may have as to the approach I took to do this.

Update: I've just fixed the link to the code, which broke when I re-organised my site.

Trackbacks

TrackBack URL for this entry:
http://alastairs-place.net/movabletype/mt-tb.cgi/12.

Comments

The link seems to be broken again. :-(

Not any more it isn't. I messed-up and forgot to move the file to the right place :-(

At least on 10.3, [image PDFRepresentation] crashes if the image was created from a PDF with the following exception:

2005-02-05 18:49:25.889 DrawBot[4660] *** -focusStack only defined for abstract class. Define -[PDFGraphicsContext focusStack]!

Do you have any idea how to implement focusStack and setFocusStack?

(I'm actually not so much interested in the PDFRepresentation category on NSImage, but rather I'm looking for a way to draw into a CGContext with Cocoa drawing primitives. Your PDFGraphicsContext class seems to do most of that just fine, as well as it being pretty much the ONLY example on line of how to do this. Thanks for publishing this!)

I would be inclined to try making -focusStack return nil and making -setFocusStack a no-op. If that doesn't work, then it'd be worth printing the type of the object (i.e. NSLog (@"-setFocusStack: class %@, object %@", [(id)object class], object)) that gets passed in to -setFocusStack and see if you can work anything out from that.

Failing that, I think you'll need to ask Apple to help... but if you find out, please post the answer in a comment here so that others can benefit from your experience.

return nil or return NULL (since it's a void *) is working fine to work around this issue.

Post a comment

If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thank-you for your patience.

(Your e-mail address will not be displayed or included in any pages served on this site; nor will you get any spam as a result.)

A live preview of your comment will be displayed below. It should refresh automatically when you stop typing, but if not then the “Preview” button above will update it.

Live Comment Preview