1

你好,我是iOS的初学者我想问一件事......我创建了一个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 但我无法解决这个问题..

4

2 回答 2

1

这是使用它的正确代码我可以将生成的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];

}
于 2013-07-24T05:09:25.323 回答
0

如果我没记错的话,那么这条线有问题,现在我已经这样编辑了。

//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);
于 2013-07-24T07:28:37.687 回答