将PDF放入NSData [英] Put PDF into NSData

查看:76
本文介绍了将PDF放入NSData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将PDF放入 NSData ?我在应用程序的文档目录中将PDF的位置作为字符串。当我尝试通过电子邮件发送时,我会在电子邮件正文中看到PDF(与查看附件图标相比。我不知道这是否正常)。但是当我在另一端收到电子邮件时,它没有PDF扩展名。我究竟做错了什么?谢谢。

How do I put my PDF into NSData? I have the location of the PDF as a string in my Documents Directory of the app. When I try to email it, I see the PDF in the body of the email (vs seeing an attachment icon. I don't know if that's normal or not). But when I receive the email on the other end, it does not have a PDF extension. What am I doing wrong? Thanks.

NSString *documentsDirectory = [self GetURLForPDF]; // I know this name is bad since it is really a NSString
NSLog(@"DocumentsDirectory: %@", documentsDirectory);
NSString *pdfName = [NSString stringWithFormat:@"%@/%@.pdf", documentsDirectory, title];
NSLog(@"pdfName: %@", pdfName);
NSData *pdfData = [NSData dataWithContentsOfFile:pdfName];
[mailComposer addAttachmentData:pdfData mimeType:@"application/pdf" fileName:title];    
[self presentModalViewController:mailComposer animated:YES];


推荐答案

根据pdfName变量的设置方式,看起来您的标题值不包括PDF后缀。您是否尝试过:

Based on how the pdfName variable is being set, it looks like your "title" value does not include the PDF suffix. Have you tried:

NSString *documentsDirectory = [self GetURLForPDF]; // I know this name is bad since it is really a NSString
NSLog(@"DocumentsDirectory: %@", documentsDirectory);
NSString *fullTitle = [NSString stringWithFormat:@"%@.pdf", title];
NSString *pdfName = [NSString stringWithFormat:@"%@/%@", documentsDirectory, fullTitle];
NSLog(@"pdfName: %@", pdfName);
NSData *pdfData = [NSData dataWithContentsOfFile:pdfName];
[mailComposer addAttachmentData:pdfData mimeType:@"application/pdf" fileName:fullTitle];    
[self presentModalViewController:mailComposer animated:YES];

这篇关于将PDF放入NSData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆