gpt4 book ai didi

ios - pdf 截图 附件 邮件

转载 作者:行者123 更新时间:2023-11-29 03:34:50 25 4
gpt4 key购买 nike

我在将屏幕截图图像从 ipad 转换为 pdf 并将其附加到电子邮件中时遇到一些问题。我不明白问题出在哪里。

有人可以帮助我吗?非常感谢您的帮助。

我的调试区:

2013-10-14 12:28:20.056 emailallegato[1309:60b] documentDirectoryFileName: /var/mobile/Applications/F4BCEBFD-3684-45A4-8D78-D88ECA5E44F4/Documents/Test.pdf

这是我的代码:

-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{

NSMutableData *pdfData = [NSMutableData data];

UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();

[aView.layer renderInContext:pdfContext];

UIGraphicsEndPDFContext();

NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);

NSString* documentDirectory = [documentDirectories objectAtIndex:0];
NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];

[pdfData writeToFile:documentDirectoryFilename atomically:YES];
NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
}

- (IBAction)iniva:(id)sender
{

[self createPDFfromUIView:self.view saveToDocumentsWithFileName:@"Test.pdf"];

NSString *path = [[NSBundle mainBundle] pathForResource:@"Test" ofType:@"pdf"];
NSData *myData = [NSData dataWithContentsOfFile:path];

MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;

if([MFMailComposeViewController canSendMail]){

[mail setToRecipients:[NSArray arrayWithObjects:@"pdftest@gmail.com", nil]];
[mail setSubject:@"Oggetto "];
[mail setMessageBody:@"Messaggio e-mail" isHTML:NO];
[mail addAttachmentData:myData mimeType:@"application/pdf" fileName:@"Material Details.pdf"];


[self presentViewController:mail animated:YES completion:NULL];
}}

最佳答案

NSString *fileName1;

fileName1 = [NSString stringWithFormat:@"test.pdf"];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *saveDirectory = [paths objectAtIndex:0];
NSString *dataFilePath = [saveDirectory stringByAppendingPathComponent:fileName1];

NSData *pdfData = [NSData dataWithContentsOfFile:dataFilePath];

然后附上这个数据

这些是创建 pdf 的有用链接:

https://github.com/bygreencn/iPhonePDF

http://www.ioslearner.com/generate-pdf-programmatically-iphoneipad/

https://github.com/KurtCode/PDFKitten

http://www.ioslearner.com/convert-html-uiwebview-pdf-iphone-ipad/

关于ios - pdf 截图 附件 邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19332755/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com