2012-11-16 4 views
0

내 응용 프로그램에서 사용자는 그의 목록에 정보를 추가 할 수 있으며 마침내 그 목록을 다른 사람에게 전자 메일로 보내려고합니다. 나는 그 목록을 어떻게 내보낼 수 있을까? pdf 또는 txt 파일로 내보낼 수 있습니까?텍스트 또는 pdf로 내보내기

답변

1

좋아, 불행히도 나는 그것을 참조하지 대한 죄송 답을 볼 수있는 페이지를 잃었다. 이 마법의 코드입니다 : 이미 내 XIB 파일에서 만든 현재의 UILabel의 나에 UIView를 사용할 수 있다면 난 그냥 대신있는 NSString의, 궁금해

-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename 
{ 
    // Creates a mutable data object for updating with binary data, like a byte array 
    NSMutableData *pdfData = [NSMutableData data]; 

    // Points the pdf converter to the mutable data object and to the UIView to be converted 
    UIGraphicsBeginPDFContextToData(pdfData, mainView.bounds, nil); 
    UIGraphicsBeginPDFPage(); 
    CGContextRef pdfContext = UIGraphicsGetCurrentContext(); 


    // draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData 

    [mainView.layer renderInContext:pdfContext]; 

    // remove PDF rendering context 
    UIGraphicsEndPDFContext(); 

    // Retrieves the document directories from the iOS device 
    NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES); 

    NSString* documentDirectory = [documentDirectories objectAtIndex:0]; 
    NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename]; 

    // instructs the mutable data object to write its context to a file on disk 
    [pdfData writeToFile:documentDirectoryFilename atomically:YES]; 
// NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename); 
} 
1

iOS5를 검색하는 경우 this Link을 확인하십시오.

http://www.raywenderlich.com/6581/how-to-create-a-pdf-with-quartz-2d-in-ios-5-tutorial-part-1

편집이 같은 UIelements를 사용 : 나는이 코드를 사용

[yourView.layer renderInContext:UIGraphicsGetCurrentContext()] 
+0

감사 SIBA, 나는 그 전에 튜토리얼 빨간색 * textToDraw = @ "Hello World" – Rudi

+1

http://stackoverflow.com/questions/9554670/how-to-export-uiview-to-pdf-file 이것이 도움이 될 것입니다. –

관련 문제