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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to