iphone - 当我们通过iPhone设备发送电子邮件作为电子邮件时,只有屏幕页面发送的不是所有页面?

  显示原文与译文双语对照的内容

你好,我是初学者,我想问一个问题。 我创建一个PDF并通过该设备发送电子邮件。 我正在发送邮件。 收到邮件成功,但没有得到pdf的所有页面。 我只有一个网页在iPhone屏幕上。如何解决这个问题?


 -(IBAction)openMail:(id)sender
 {
 if ([MFMailComposeViewController canSendMail])
 {

 NSMutableData *pdfData = [NSMutableData data];
 UIGraphicsBeginPDFContextToData(pdfData, self.view.bounds, nil);
 UIGraphicsBeginPDFPage();

 [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

 UIGraphicsEndPDFContext();


 MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];

 mailer.mailComposeDelegate = self;

 [mailer setSubject:@"A Message from CloudChowk"];

 [mailer addAttachmentData:pdfData mimeType:@"pdf" fileName:@"abcd.pdf"];

 NSLog(@"mailer %@",mailer);


 NSString *emailBody = @"Patient Report";

 [mailer setMessageBody:emailBody isHTML:NO];

 [self presentViewController:mailer animated:YES completion:nil];

 }

 else
 {
 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"message:@"Your device doesn't support the composer sheet"delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];

 [alert show];

 }


}
 - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
 {
 switch (result)
 {
 case MFMailComposeResultCancelled:
 {
 NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued.");
 break;
 }
 case MFMailComposeResultSaved:
 {
 NSLog(@"Mail saved: you saved the email message in the drafts folder.");
 break;
 }
 case MFMailComposeResultSent:
 {
 NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send.");
 break;
 }
 case MFMailComposeResultFailed:
 {
 NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error.");
 break;
 }
 default:
 NSLog(@"Mail not sent.");
 break;
 }

 [self dismissViewControllerAnimated:YES completion:nil];
 }

我使用这个功能运行成功并发送电子邮件,但不发送所有页面。"。"。请解决这个问题。"。"。


 UIGraphicsBeginPDFContextToData(pdfData, self.view.bounds, nil);

我怀疑这条线是 self.view.bounds,但我不能解决这个问题。

时间: 作者:

这是正确的代码使用这个我可以发送所有页面生成的pdf文件作为电子邮件。


 if ([MFMailComposeViewController canSendMail])
 {

 MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];

 mailer.mailComposeDelegate = self;

 [mailer setSubject:@"A Message from CloudChowk"];


 NSLog(@"file name %@",fileName);
 NSData *data=[NSData dataWithContentsOfFile:fileName];
//NSLog(@"data %@",data);
 [mailer addAttachmentData:data mimeType:@"pdf" fileName:@"myPDF.pdf"];

 NSLog(@"mailer %@",mailer);

 NSString *emailBody = @"Patient Report";

 [mailer setMessageBody:emailBody isHTML:NO];

 [self presentViewController:mailer animated:YES completion:nil];

}

else
{
 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"message:@"Your device doesn't support the composer sheet"delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];

 [alert show];

}

如果我没有错,那这条线就出现了,现在我编辑了这个。


//In this line you are only capturing view bound frame, If you are using scrollView in it then refer its bound relative to scrollView (content Size).
UIGraphicsBeginPDFContextToData(pdfData, self.scrollView.contentSize, nil);

作者:
...