[英]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.