• 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
Re: Losing attachments when saving rtfd
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Losing attachments when saving rtfd


  • Subject: Re: Losing attachments when saving rtfd
  • From: "email@hidden" <email@hidden>
  • Date: Wed, 25 Apr 2012 10:24:55 +0100

On 24 Apr 2012, at 17:31, Matthew Weinstein wrote:

> Dear programmers,
>
> Trying to save an RTFD from an NSAttributedString with attachements. The text saves; the images don't...
>
> I've been scouring the web but can't seem to figure out what's wrong.
>
> I have a NSAttributedString with attachments. I check that the string really has the attachments by using setAttributedString to the textstorage of a NSTextView, and voila, there it is.
>
> But I can't seem to save the attachment. This is what I'm trying:
>
> 	//this is a category I found on the interwebs
> 	myimagets = [[NSTextAttachment alloc] initWithAnImage: myimage];
> 	//get doc string
> 	//replace with the attributed string
>
> 	myattstr =  [NSMutableAttributedString attributedStringWithAttachment: myimagets];
>
> 	//stick on a little text at the end to see how it handles both...
> 	addon = [[NSMutableAttributedString alloc] initWithString: @"and here's the extra bit"];
> 	[myattstr appendAttributedString: addon];
>
> 	//this is my test to see if the attachment is really there: it works!
> 	[[myTextView textStorage] setAttributedString: myattstr];
>
>
> 	//here's what fails:
> 	myfw = [myattstr RTFDFileWrapperFromRange: NSMakeRange(0, [myattstr length])
> 						   documentAttributes:nil];
> 	[myfw writeToFile: [@"~/Desktop/outfile.rtfd" stringByExpandingTildeInPath]
> 		   atomically:YES updateFilenames:YES];
> What's created is an rtfd with only the rtf file in it and no images....
>
> Thoughts? Help?
I have used the following, might be worth a try.

NSFileWrapper *wrapper = [attributedStringResource
                                            RTFDFileWrapperFromRange:NSMakeRange(0, [self.attributedStringResource length])
                                            documentAttributes:nil];

success = [wrapper writeToURL:[NSURL fileURLWithPath:[path stringByExpandingTildeInPath]]
                                        options:NSFileWrapperWritingAtomic & NSFileWrapperWritingWithNameUpdating
                                        originalContentsURL:nil
                                        error:&error];

Regards

Jonathan Mitchell
Mugginsoft LLP

================================================
KosmicTask - the Integrated Scripting Environment for OS X.
http://www.mugginsoft.com/KosmicTask
================================================










_______________________________________________

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

References: 
 >Losing attachments when saving rtfd (From: Matthew Weinstein <email@hidden>)

  • Prev by Date: Re: Canceling a NSURLConnection
  • Next by Date: Re: Displaying history - potential ways to do it
  • Previous by thread: Losing attachments when saving rtfd
  • Next by thread: Re: Losing attachments when saving rtfd
  • Index(es):
    • Date
    • Thread