Open NSData (PDF content) in UIWebview which is stored in Sqlite

I want to open pdf in webview, but the scenario is different here, I saved PDF content as NSData in sqlite table (blob datatype), I got success when I inserted data into sqlite table, but as soon as I get blob in NSData and trying to open this data in a WebView, it gives me an error - could not find PDF header: `% PDF 'not found.
I am using loadview method for webview to load data

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

I did a lot of searching and also went through other questions but didn't find a sufficient answer.

thank you
Mayur

+3


source to share


3 answers


The first four bytes of any PDF file %PDF

. This tells you that by the time you try to display the data, it is not a PDF file (or if so, the beginning has been chopped off).



Either you put the corrupted data into the SQLite database, or you corrupt it when you retrieve it. This should be easy to confirm one way or another by looking at the data in the database using command line tools.

+1


source


Have you tried dumping the NSData conversion to NSString and then dumping it to the console? The PDF must start with "% PDF-1.2 ......", you must make sure the blob data from sqlite is full pdf content.



+1


source


If you are opening a file to print from a web view, you want to use the UIPrintViewFormatter 'viewPrintFormatter' method to assign your webview to be formatted. Then you add your UIPrintViewFormatter instance to your UIPrintInteractionController instance.

Here's an example using UIPrintViewFormatter:

 UIViewPrintFormatter *viewPrintFormatter = [self.contentWebView  viewPrintFormatter];
[printInteractionController setPrintFormatter:viewPrintFormatter];

      

0


source







All Articles