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

Binary to pdf convert without store in documentsDirectory in obj c

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

  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];行 并检查