Berry Blue
Berry Blue

Reputation: 16482

Rich Text Format Directory File to NSAttributedString

Is it possible to convert an RFTD (Rich Text Format Directory) package to an NSAttributedString in iOS? This is a package that includes an RTF (Rich Text Format) file plus other files like images that are included in the rich text file.

I can convert a normal RTF file like this but I don't know how to convert an RFTD package to an NSData object. I also don't know if it's then possible to convert that NSData object to an NSAttributedString object.

NSString *path = [[NSBundle mainBundle] pathForResource:@"Name" ofType:@"rtf"];
NSData *data = [NSData dataWithContentsOfFile:path];

NSError *error = nil;
NSAttributedString *string = [[NSAttributedString alloc] initWithData:data options:@{NSDocumentTypeDocumentAttribute: NSRTFTextDocumentType} documentAttributes:nil error:&error];

Upvotes: 0

Views: 789

Answers (1)

battlmonstr
battlmonstr

Reputation: 6290

It looks like all RTFD-related functions are deliberately cut off from iOS, but since RTFD is just a directory with a normal RTF file, you could try accessing it as such.

If you need attachments, based on the RTF docs here it seems that you can find a marker "NeXTGraphic" inside the RTF file string

{{\NeXTGraphic attachment \widthN \heightN} string}

where "attachment" will be a file name.

Similar question here: Read RTFD data in IOS

Upvotes: 1

Related Questions