2012-11-16 40 views
0

在我的應用程序中,用戶可以將一些信息添加到他的列表中,最後他想通過電子郵件將該列表發送給其他人。我只是想知道如何導出該列表?將它導出爲pdf或txt文件可以嗎?!導出文本或pdf

回答

1

好,我用這個代碼,不幸的是我失去了我找到了答案約不引用它很抱歉的頁面。這是魔碼:

-(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

感謝思巴,我前紅認爲,教程,我只是想知道,而不是NSString的,如果它可以使用,我已經在我的廈門國際銀行文件創建當前的UILabel或UIView的,* textToDraw = @「Hello World」 – Rudi

+1

http://stackoverflow.com/questions/9554670/how-to-export-uiview-to-pdf-file這可能會幫助你。 –