• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Creating a file containing both an image and text
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Creating a file containing both an image and text


  • Subject: Creating a file containing both an image and text
  • From: Arthur C. <email@hidden>
  • Date: Sat, 12 Jan 2008 22:50:11 +0100
  • Importance: Normal

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Creating a file containing both an image and text
      • From: Andrew Farmer <email@hidden>
  • Prev by Date: re: core data subentities
  • Next by Date: Starting my application at user login
  • Previous by thread: re: core data subentities
  • Next by thread: Re: Creating a file containing both an image and text
  • Index(es):
    • Date
    • Thread