Re: Put pdf on pasteboard / NSData from NSImage?
Re: Put pdf on pasteboard / NSData from NSImage?
- Subject: Re: Put pdf on pasteboard / NSData from NSImage?
- From: Geoff Levner <email@hidden>
- Date: Sat, 9 Apr 2005 06:42:42 +0200
You can copy a PDF image representation to the pasteboard like this:
+ (void) copyPDFToPasteboard:(NSPDFImageRep*)pdfRep
{
NSPasteboard *pb = [NSPasteboard generalPasteboard];
NSArray *types = [NSArray arrayWithObject:NSPDFPboardType];
[pb declareTypes:types owner:nil];
[pb setData:[pdfRep PDFRepresentation] forType:NSPDFPboardType];
}
If you don't have a pointer to the PDF image representation, you can
get it through NSImage's -representations method like this:
+ (NSPDFImageRep*) getPDFRepFromImage:(NSImage*)image
{
NSArray *reps = [image representations];
int i, n = [reps count];
for (i = 0; i < n; i++) {
NSImageRep *rep = [reps objectAtIndex:i];
if ([rep isKindOfClass:[NSPDFImageRep class]])
return (NSPDFImageRep*) rep;
}
return nil;
}
Geoff
On 9 Apr 2005, at 03:23, Julian Dreißig wrote:
I have a NSImage loaded with a pdf (e.g. pasted into). How can I put
this pdf on a pasteboard? As far as I can see I need the image in a
NSData representation (-setData:forType:). How do I get such a NSData
from a NSImage _without_ showing the image in a NSView?
Or is there an easier way to do what I want to do?
Thanks a lot,
- Julian
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden