Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pdf as an email attachment in iOS device [closed]

I would like to attach pdf created as an email attachment. I used following tutorial to create pdf on iOS device.

The downloaded pdf can be viewed at this path: /Users/”Username”/Library/Application Support/iPhone Simulator/”Your App Directory”.

I have not tried running this on ios device but I need to attach it as an email.

Link for tutorial is : http://www.ioslearner.com/generate-pdf-programmatically-iphoneipad/

Any suggestion.

like image 540
user1140780 Avatar asked Jan 13 '12 05:01

user1140780


People also ask

Why can't I open PDF from email attachments on my iPhone?

If you're trying to open a PDF on an iPad or iPhone and it appears blank, you need to set Adobe Reader as your default for opening PDF files on your device. đź’ˇTip: Select the Preview icon to quickly preview PDFs without downloading them.

Where did my PDF go on my iPhone?

Your PDF opens and automatically saves in the Books app. You can find it later in the Library tab.

Why won't my email attachments open on my iPhone?

You won't be able to open or view an email attachment on your iPhone until it has downloaded completely. If you see that the attachment is still Downloading or when the download circle is not yet complete, then wait until it finished before opening the file.


1 Answers

Create a MFMailComposeViewController and call addAttachmentData:mimeType:fileName:. The data will be the PDF you created. The mimeType will be application/pdf. And the fileName will be the name of the file in the email attachment. The code might look like something below:

From the tutorial you'll need to render your PDF into a NSMutableData object:

NSMutableData *pdfData = [NSMutableData data];
UIGraphicsBeginPDFContextToData(pdfData, bounds, nil);

Then at some point in the future you'll need to pass that pdfData to the MFMailComposeViewController.

MFMailComposeViewController *vc = [[[MFMailComposeViewController alloc] init] autorelease];
[vc setSubject:@"my pdf"];
[vc addAttachmentData:pdfData mimeType:@"application/pdf" fileName:@"SomeFile.pdf"];
like image 126
Evan Avatar answered Oct 23 '22 09:10

Evan