Question

I am trying to save a pdf file in SQLite. I think it will be possible by saving the pdf file as blob. And the problem starts here, how to view that file within the iPhone app now? I know it can be done using this code:-

 @interface PDFViewController : UIViewController  {
        UIWebView *webView;
        NSURL *pdfUrl;
    }

    @property (nonatomic, retain) IBOutlet UIWebView *webView;
    @property (nonatomic, retain) NSURL *pdfUrl;

    @end



@implementation PDFViewController

@synthesize webView, pdfUrl;
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Tells the webView to load pdfUrl
        [webView loadRequest:[NSURLRequest requestWithURL:pdfUrl]];
    }

But what should be the value of the pdfUrl,I am confused... And if I retrieve it from the DB it will be in a blob format(methinks) so how to convert it into a NSdata object?

Thank You All.

Was it helpful?

Solution

The problem is that WebView does the URL loading, and it won't understand things like non-http requests; yet your application is trying to serve the data. So basically, you're out of luck, unless you can deserialise the blob out of the sqllite database, write it to a file (in /tmp, say) and then open up a file:/// URL from the NSWebView - but I don't believe that the object will let you do that.

You might be able to invoke the [UIWebView loadData:MIMEType:textEncodingName:baseURL:] method, which will allow you to extract the NSData blob from the sqllite database, supply a mime-type of application/pdf, stick in a dummy text encoding (UTF-8) and base URL, and then it might do what you want. But I'd be tempted to try that at least.

OTHER TIPS

the pdfUrl is the web address of the PDF you are tryign to download from the website. (ie http://website.com/mypdf.pdf)

Read the documentation on NSData, it has a method to allow you to create NSData objects based no what you pull out using sqlite.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top