Search code examples
iphoneobjective-cios5

When we send pdf as email through iPhone device then only screen page send not all pages why?


hello i am beginner in iOS I want to ask one thing... I create a PDF and send as email through the device.. I am sending mail right.... I get mail successfully but I don't get all pages of the PDF... I got only one page which are on iPhone screen ...how to solve this problem?

 -(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];
 }

I am using this function which runs successfully and sends email but not send all pages ...please solve this problem ....

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

I doubt this line as self.view.bounds but i can't solve this problem ..


Solution

  • this is right code using this I can send all pages of generated pdf file as email..

       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];
    
    }