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
source to share
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.
source to share
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];
source to share