如何将PDF放入NSData
?我在应用程序的文档目录中将PDF的位置作为字符串。当我尝试通过电子邮件发送时,我会看到电子邮件正文中的PDF(与查看附件图标相比。我不知道这是否正常)。但是当我在另一端收到电子邮件时,它没有PDF扩展名。我究竟做错了什么?感谢。
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];
答案 0 :(得分:9)
根据pdfName变量的设置方式,您的“标题”值看起来不包含PDF后缀。你试过了吗?
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];