Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Creating a file containing both an image and text



I would like to save screenshots from my program (as an image), with additional text data underneath, in the same file.
Using the OS-X 'screencapture' utility I can either create a PNG or PDF file, or send one of these to the clipboard. 
I found several classes to import data from the clipboard (NSPasteBoard), and the NSAttributedString class which can write an RTFD file. That would be OK for this purpose. However, currently I can't get it to work.
 
Question: how can I store an image and some text in one file in the most convenient (simple) way? Which file format should it be, PDF or RTFD, or something else?
 
The following code extracts the (pdf) data from the pasteboard, and then attempts to create an RTFD file wrapper out of it.
 
NSPasteboard *pb = [NSPasteboard generalPasteboard];NSArray *supportedTypes = [NSArray arrayWithObject: NSPDFPboardType];NSString *bestType = [pb availableTypeFromArray:supportedTypes];
if (bestType != nil){   NSData * RTFDData = [pb dataForType: NSPDFPboardType];   NSError * error;   NSDictionary * dict; 
   NSMutableAttributedString * myString = [[NSMutableAttributedString   alloc] initWithData: RTFDData   options:nil documentAttributes:&dict error:&error];   NSFileWrapper * fileWrapper = [myString RTFDFileWrapperFromRange:      NSMakeRange(0, [myString length]) documentAttributes: dict];   [fileWrapper writeToFile: [NSString stringWithFormat:      @"%@/screenshot.rtfd", myCurrentDirectoryPath] atomically: YES      updateFilenames: YES];
}
NSMutableAttributedString's initWithData call gives 'plain text' back in the documentAttributes dict, meaning it didn't recognize the PDF type. The rest does not produce a sensible RTFD file.
 
 
Thanks for your time,
 
Arthur C.
 
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.