gpt4 book ai didi

ios - 二进制到pdf转换而不存储在obj c的documentsDirectory中

转载 作者:行者123 更新时间:2023-12-01 20:07:22 26 4
gpt4 key购买 nike

让二进制代码使用 dataFromBase64String 将其转换为 nsdata。并成功加载它的 web View 。但是希望pdf文件不存储在documentsDirectory中。需要添加一个按钮单击用户单击该按钮,然后将发生二进制到pdf转换并显示在Web View 中。这是我的代码。怎么可能帮助我。提前谢谢。

  NSString *binaryString =@"Binary code to change";
myData = [NSData dataFromBase64String: binaryString];
[self savePDF:myData];


- (void)savePDF:(NSData *)pdfContent
{
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask ,YES );
NSString *documentsDirectory = [paths objectAtIndex:0];

finalPath = [documentsDirectory stringByAppendingPathComponent:@"myPdf.pdf"];
NSLog(@"%@",finalPath);
NSURL *url = [NSURL fileURLWithPath:finalPath];
[pdfContent writeToURL:url atomically:YES];
[aWebView loadRequest:[NSURLRequest requestWithURL:url]];
}

最佳答案

如果您不想将 pdf 文件存储到 DocumentsDirectory 然后
尝试关注,希望它对你有用

NSString *binaryString =@"Binary code to change";
myData = [NSData dataFromBase64String: binaryString];
[self savePDF:myData];


- (void)savePDF:(NSData *)pdfContent
{
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask ,YES );
NSString *documentsDirectory = [paths objectAtIndex:0];

finalPath = [documentsDirectory stringByAppendingPathComponent:@"myPdf.pdf"];
NSLog(@"%@",finalPath);
NSURL *url = [NSURL fileURLWithPath:finalPath];
//[pdfContent writeToURL:url atomically:YES];
[aWebView loadRequest:[NSURLRequest requestWithURL:url]];
}

评论 //[pdfContent writeToURL:url atomically:YES];线
并检查

关于ios - 二进制到pdf转换而不存储在obj c的documentsDirectory中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38497225/

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