Skip navigation.
 
mlCreating a file containing both an image and text
FROM : Arthur C.
DATE : Sat Jan 12 22:50:11 2008

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_removed>)

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_removed>

This email sent to <email_removed>

Related mailsAuthorDate
mlCreating a file containing both an image and text Arthur C. Jan 12, 22:50
mlRe: Creating a file containing both an image and text Andrew Farmer Jan 12, 23:55
mlRE: Creating a file containing both an image and text Arthur C. Jan 14, 16:57
mlRE: Creating a file containing both an image and text Arthur C. Jan 17, 21:29
mlRe: Creating a file containing both an image and text haller Jan 18, 09:07