-1

I am trying to download one pdf using NSURLConnection methods i got some data in didReceiveData method now i want to convert that data into pdf and display it on webview while downloading whole pdf so that user can view some part of pdf.

Thanks in advance.

Sachin Amrale
  • 277
  • 1
  • 9
  • 3
    Possible duplicate of [How to download PDF and store it locally on iPhone?](http://stackoverflow.com/questions/2226615/how-to-download-pdf-and-store-it-locally-on-iphone) – ChintaN -Maddy- Ramani Aug 29 '16 at 07:01
  • 1
    BTW, don't use the deprecated `NSURLConnection` anymore. Use `NSURLSession` (or load it directly into a web view). – Rob Aug 29 '16 at 07:22
  • Actually the file is still in downloading state.Suppose i have to download a pdf of 10mb from server. i started downloading it when i got 5 mb of data, i want to access and preview that data as pdf while the rest of the pdf is downloading. – Sachin Amrale Aug 30 '16 at 04:50

1 Answers1

0

You can can do that by using following code:

Directly load in WebView:

//Pass your NSData in PdfData

[webview loadData:PdfData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];

OR

Use CGPDFDocumentCreateWithProvider to generate pdf and then load to webview:

//NSData to pdf
NSData *contentData               = //Your NSData
CFDataRef PDFData                 = (CFDataRef)contentData;
CGDataProviderRef provider        = CGDataProviderCreateWithCFData(PDFData);
CGPDFDocumentRef genPdf           = CGPDFDocumentCreateWithProvider(provider);

Also check: Loading NSData into a UIWebView

Community
  • 1
  • 1
Ronak Chaniyara
  • 5,335
  • 3
  • 24
  • 51