Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Oops, you were asking about Cocoa and this is Cocoa Touch, but I'll leave it here as it may be some use (at least to others who find this later).</p> <p>You can draw things in the view and then put what's there into a pdf.</p> <p>This code will take what's drawn in a UIView (called sheetView here), put it into a pdf, then put that as an attachment in an email (so you can see it for now). You'll need to reference the protocol MFMailComposeViewControllerDelegate in your header.</p> <pre><code>if ([MFMailComposeViewController canSendMail]) { //set up PDF rendering context NSMutableData *pdfData = [NSMutableData data]; UIGraphicsBeginPDFContextToData(pdfData, sheetView.bounds, nil); UIGraphicsBeginPDFPage(); //tell our view to draw (would normally use setNeedsDisplay, but need drawn now). [sheetView drawRect:sheetView.bounds]; //remove PDF rendering context UIGraphicsEndPDFContext(); //send PDF data in mail message as an attachment MFMailComposeViewController *mailComposer = [[[MFMailComposeViewController alloc] init] autorelease]; mailComposer.mailComposeDelegate = self;If [mailComposer addAttachmentData:pdfData mimeType:@"application/pdf" fileName:@"SheetView.pdf"]; [self presentModalViewController:mailComposer animated:YES]; } else { if (WARNINGS) NSLog(@"Device is unable to send email in its current state."); } </code></pre> <p>You'll also need this method...</p> <pre><code>#pragma mark - #pragma mark MFMailComposeViewControllerDelegate protocol method //also need to implement the following method, so that the email composer can let //us know that the user has clicked either Send or Cancel in the window. //It's our duty to end the modal session here. -(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { [self dismissModalViewControllerAnimated:YES]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload