2013-07-05 3 views
1

pdf 확장자가있는 첨부 파일로 html 텍스트를 메일로 보내야합니다.ios에서 첨부 파일로 html 텍스트를 pdf 형식으로 보내십시오.

코드 :

MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init]; 
    mailViewController.mailComposeDelegate = self; 
    NSArray *toReceipents =[NSArray arrayWithObjects:@"", nil]; 
    [mailViewController setToRecipients:toReceipents]; 
    [mailViewController setSubject:strMailMessage]; 
    NSLog(@"Mail Message:%@ %@",strMailMessage,appDelegate.strShareText); 
    NSData* data = [appDelegate.strShareText dataUsingEncoding:NSUTF8StringEncoding]; 
    [mailViewController setMessageBody:appDelegate.strShareText isHTML:YES]; 
    [mailViewController addAttachmentData:data mimeType:@"application/pdf" fileName:@"Medication file.pdf"]; 
    [self presentModalViewController:mailViewController animated:YES]; 
    [mailViewController release]; 

참고 : 나는 같은 text.but 무엇입니까 pdf 파일을 다운로드 할 때 내가 PDF 문서

답변

0

좋은 코드뿐만 HTML 표 형식의 텍스트를 표시하려면

- (IBAction)mailCompose:(id)sender { 

     MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init]; 
     mail.mailComposeDelegate = self; 

     [mail setSubject:@"Hello World!"]; 
     NSArray *toRecipients = [NSArray arrayWithObjects:@"e-mail here or leve empty", nil]; 

     [mail setToRecipients:toRecipients]; 
     NSString *emailBody = @"Body message App</b><br /><a href='https://itunes.apple.com/it/app/yourApp/id'>Download Free on AppStore!</a>"; 

     NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; 
     NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"myVoice.caf"]; 
     NSData *myData = [NSData dataWithContentsOfFile:filePath]; 
     [mail addAttachmentData:myData mimeType:documentsDirectory fileName:@"myVoice.caf"]; 


     [mail setMessageBody:emailBody isHTML:YES]; 
     mail.modalPresentationStyle = UIModalPresentationPageSheet; 
     [self presentViewController:mail animated:YES completion:nil]; 

} 
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { 

    switch (result) { 
     case MFMailComposeResultCancelled: 
      NSLog(@"Cancelled"); 
      break; 
     case MFMailComposeResultSaved: 
      NSLog(@"Saved"); 
      break; 
     case MFMailComposeResultFailed: 
      NSLog(@"Faild"); 
      break; 
     case MFMailComposeResultSent: 
      NSLog(@"Sent"); 
      break; 
     default: 
      NSLog(@"Default"); 
      break; 
    } 

    [self dismissViewControllerAnimated:YES completion:nil]; 

} 

Enjy이 당신에게

을 도울 수 있기를 바랍니다 :)이 시도