简体   繁体   中英

Binary to pdf convert without store in documentsDirectory in obj c

Have a Binary code convert it to nsdata using dataFromBase64String. And load it web view successfully. 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. 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

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]; line and check

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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