NSImage -PDFRepresentation method (was Re: DragDropImageView (solution))
NSImage -PDFRepresentation method (was Re: DragDropImageView (solution))
- Subject: NSImage -PDFRepresentation method (was Re: DragDropImageView (solution))
- From: "Alastair J.Houghton" <email@hidden>
- Date: Wed, 17 Sep 2003 19:16:19 +0100
Lorenzo was trying to get PDF data corresponding to an NSImage, and the
best we could come up with was something like:
NSImageView *pdfView = [[NSImageView alloc]
initWithFrame:NSMakeRect(0,0,
[gCroppedImage size].width,
[gCroppedImage size].height)];
[pdfView setImage:gCroppedImage];
NSData *pfdData;
pfdData = [PDFView dataWithPDFInsideRect:[pdfView bounds]];
[pdfView release];
[sender set
Data:pfdData forType:NSPDFPboardType];
which seemed a bit of a round-about way of getting a PDF wrapper for an
image, especially as Quartz supports PDF graphics contexts. I was a
bit surprised to find that it wasn't possible to create a suitable
NSGraphicsContext (if you set the attributes to make a PDF context, you
get a complaint on the console that it only supports files at present),
nor does it seem to be possible to do this using an NSPDFImageRep
(there's no [obvious] way to create an empty one)...
Anyway, I had a bash at implementing a -PDFRepresentation method on
NSImage, using a Quartz PDF graphics context via a custom subclass of
NSGraphicsContext... the results are available to anyone who wants at
http://www.alastairs-place.net/blog/archives/2003_09.html
I'd be interested to hear any comments (especially from the more
experienced Cocoa-heads) on the general method (i.e. subclassing
NSGraphicsContext); it's a lot more code than Lorenzo's solution, but
is it any better? Or is it worse? On the one hand it generates PDF in
a less round-about way, but on the other, perhaps subclassing
NSGraphicsContext isn't such a great idea?
Kind regards,
Alastair.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.