2013-05-02 27 views
-3

我正在做一個iPhone應用程序,其中我擊中了一部分是..當用戶按下提交按鈕我想發送PDF格式的整個表格到特定的電子郵件。 任何幫助將非常感激。當按下提交按鈕時發送整個表格在Pdf格式

謝謝

+0

這個問題太模糊和廣泛。請縮小特定問題的範圍並澄清您的問題。 – rmaddy 2013-05-02 04:24:54

回答

3
-(IBAction)takeScreenShot 
{ 
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) 
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale); 
else 
    UIGraphicsBeginImageContext(self.view.bounds.size); 
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
UIImageView *newImage = [[UIImageView alloc] initWithImage:image]; 
UIGraphicsEndImageContext(); 

[self createPDFfromUIView:newImage saveToDocumentsWithFileName:@"SecondScreen1.pdf"]; 
} 


-(void)createPDFfromUIView:(UIImageView*)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, aView.view.bounds, nil); 
UIGraphicsBeginPDFPage(); 

// draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData 
[aView.layer renderInContext:UIGraphicsGetCurrentContext()]; 

// 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); 
} 

這將是工作。