pdf 作为 iOS 设备中的电子邮件附件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8846338/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
pdf as an email attachment in iOS device
提问by user1140780
I would like to attach pdf created as an email attachment. I used following tutorial to create pdf on iOS device.
我想附上作为电子邮件附件创建的 pdf。我使用以下教程在 iOS 设备上创建 pdf。
The downloaded pdf can be viewed at this path: /Users/”Username”/Library/Application Support/iPhone Simulator/”Your App Directory”.
下载的pdf可以在这个路径查看:/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.
我还没有尝试在 ios 设备上运行它,但我需要将它作为电子邮件附加。
Link for tutorial is : http://www.ioslearner.com/generate-pdf-programmatically-iphoneipad/
教程链接是:http: //www.ioslearner.com/generate-pdf-programmatically-iphoneipad/
Any suggestion.
任何建议。
回答by Evan
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:
创建一个MFMailComposeViewController
并调用addAttachmentData:mimeType:fileName:
. 数据将是您创建的 PDF。mimeType 将为application/pdf
. fileName 将是电子邮件附件中文件的名称。代码可能如下所示:
From the tutorial you'll need to render your PDF into a NSMutableData object:
从教程中,您需要将 PDF 渲染为 NSMutableData 对象:
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
.
然后在将来的某个时候,您需要将该 pdfData 传递给MFMailComposeViewController
.
MFMailComposeViewController *vc = [[[MFMailComposeViewController alloc] init] autorelease];
[vc setSubject:@"my pdf"];
[vc addAttachmentData:pdfData mimeType:@"application/pdf" fileName:@"SomeFile.pdf"];