Re: Opening and Saving an RTFD
Re: Opening and Saving an RTFD
- Subject: Re: Opening and Saving an RTFD
- From: chaitanya pandit <email@hidden>
- Date: Mon, 4 Aug 2008 23:24:17 -0400
Hi,
I'm not sure what exactly you are trying to do but i believe you need
to create a NSTextAttachment from the file wrapper and then generate
an attributed string out of it.
NSFileWrapper* filewrapper = [[NSFileWrapper alloc] initWithPath:path];
NSTextAttachment *attachment = [[[NSTextAttachment alloc]
initWithFileWrapper:filewrapper]autorelease];
NSAttributedString* origFile = [NSAttributedString
attributedStringWithAttachment:attachment];
NSData *data = [origFile RTFDFromRange:NSMakeRange(0, [origFile
length]) documentAttributes:nil];
[[NSFileManager defaultManager] createFileAtPath:path contents:data
attributes:nil];
If you just want to create an attributed string from RTFD data you
can use NSAttributedString's AppKit addition method :
- (id)initWithPath:(NSString *)path documentAttributes:(NSDictionary
**)docAttributes
Then if you want to write it back, you can do the same by:
NSData *data = [origFile RTFDFromRange:NSMakeRange(0, [origFile
length]) documentAttributes:nil];
[[NSFileManager defaultManager] createFileAtPath:path contents:data
attributes:nil];
Hope this helps.
- Chaitanya
On 04-Aug-08, at 6:03 PM, Mark Munz wrote:
I must be missing something obvious here and I'm hoping someone can
point it out.
When I try to read in an RTFD and then write it back out, I lose the
attachments (images) in the file if I open it up again. I'm using a
filewrapper to write it back out. The images are still in the package,
but they are no longer in the file when opened via TextEdit.
NSFileWrapper* filewrapper = [[NSFileWrapper alloc]
initWithPath:path];
NSAttributedString* origFile = [[NSAttributedString alloc]
initWithRTFDFileWrapper:filewrapper
documentAttributes:&docAttributes];
if (origFile)
{
NSAttributedString* newFile = origFile;
if (newFile)
{
NSFileWrapper* newFilewrapper = [newFile RTFDFileWrapperFromRange:
NSMakeRange(0,
[newFile length]) documentAttributes:nil];
[newFilewrapper writeToFile:path atomically:YES
updateFilenames:YES];
}
}
To rule out any changes I might have made to the attributed string, I
just used the original string and wrote it back to demonstrate the
problem.
Your help is much appreciated. Thanks.
--
Mark Munz
unmarked software
http://www.unmarked.com/
_______________________________________________
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
_______________________________________________
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