简体   繁体   English

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

[英]Binary to pdf convert without store in documentsDirectory in obj c

Have a Binary code convert it to nsdata using dataFromBase64String. 让二进制代码使用dataFromBase64String将其转换为nsdata。 And load it web view successfully. 并成功加载Web视图。 But Want the pdf file do not store in documentsDirectory.Need to add one button click user click the button, then Binary to pdf convert will happened and display in web view. 但是要pdf文件不存储在documentsDirectory中。需要添加一个按钮,然后单击用户单击按钮,然后就会发生二进制到pdf转换并显示在Web视图中。 here my code. 这是我的代码。 How is possible help me. 怎么可能帮助我。 thanks advance. 谢谢提前。

  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]];
}

If you don't want to store pdf file to DocumentsDirectory then try following, hope it will work for you 如果您不想将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]];
}

Comment //[pdfContent writeToURL:url atomically:YES]; 评论//[pdfContent writeToURL:url atomically:YES]; line and check 线和检查

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM