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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 16:16:06  来源:igfitidea点击:

pdf as an email attachment in iOS device

iphoneobjective-ciospdf-generationemail-attachments

提问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 MFMailComposeViewControllerand 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"];

回答by Jesse Bunch

See the docsfor MFMailComposeViewController. Specifically, you're looking for the addAttachmentData:mimeType:fileName:method. That should get you going.

查看文档MFMailComposeViewController。具体来说,您正在寻找addAttachmentData:mimeType:fileName:方法。那应该能让你继续前进。