[英]How to save HTML text in RTF file
有什么方法可以将HTML字符串保存在RTF文件中。 我尝试了下面的代码。 但是RTF文件没有打开。
[strHTML writeToFile:[DOCUMENT_PATH stringByAppendingPathComponent:@"1.rtf"] atomically:YES encoding:NSUTF8StringEncoding error:nil];
请指导我。
你可以试试这个
创建NSMutableAttributedString;
NSMutableAttributedString *textView=[[NSMutableAttributedString alloc]init];
[textView appendAttributedString:[[NSAttributedString alloc]initWithString:strHTML]];
将文档类型保存到NSRTFTextDocumentType
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
NSRTFTextDocumentType,
NSDocumentTypeDocumentAttribute,
[NSNumber numberWithInteger:1],
NSCharacterEncodingDocumentAttribute,
nil];
NSData *data = [textView dataFromRange:NSMakeRange(0, [textView length])
documentAttributes:dict
error:nil];
最终写入文件
[data writeToFile:[DOCUMENT_PATH stringByAppendingPathComponent:@"1.rtf"] atomically:YES];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.