2014-07-27 2 views
0

RTF 파일에 HTML 문자열을 저장할 수있는 방법이 있습니까? 나는 아래의 코드를 시도했다. 하지만 RTF 파일이 열리지 않습니다.RTF 파일에 HTML 텍스트를 저장하는 방법

[strHTML writeToFile:[DOCUMENT_PATH stringByAppendingPathComponent:@"1.rtf"] atomically:YES encoding:NSUTF8StringEncoding error:nil]; 

안내해주세요.

+0

읽기 [워드 프로세서] (https://developer.apple.com/library 파일는, writeTo NSRTFTextDocumentType하기 /ios/documentation/Cocoa/Conceptual/AttributedStrings/Articles/HTMLFilesandAttributedStrings.html#//apple_ref/doc/uid/TP4 0014062-SW1). – duci9y

+0

'DOCUMENT_PATH '은 무엇입니까? HTML 문서의 경로? – idmean

+0

파일을 어떻게 열려고합니까? –

답변

0

이 NSMutableAttributedString 만들기 시도 할 수 있습니다;

NSMutableAttributedString *textView=[[NSMutableAttributedString alloc]init]; 
[textView appendAttributedString:[[NSAttributedString alloc]initWithString:strHTML]]; 

저장 문서 유형은

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]; 
관련 문제