Dev.Franco
Dev.Franco

Reputation: 63

Load pdf with transparent background in UIWebView

I've saved a pdf with transparent background with photoshop and import in xcode. I've create a webview and import the pdf like this:

NSString *urlAddress = [[NSBundle mainBundle] pathForResource:@"PDF_da Photoshop" ofType:@"pdf"];
NSURL *url = [NSURL fileURLWithPath:urlAddress];
NSData *data = [NSData dataWithContentsOfFile:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[wv setDelegate:self];
[wv loadData:data MIMEType:@"application/pdf" textEncodingName:@"UTF-8" baseURL:nil];

No problem to see the pdf inside the webview but without a transparent background.

Upvotes: 2

Views: 1343

Answers (1)

JFoulkes
JFoulkes

Reputation: 2429

Are you expecting to see the webview underneath the PDF? If so then this won't work. The way UIWebView displays PDFs is by swapping its subviews out with an entirely new view. To keep the webview underneath you will need to implement your own PDF view or find an existing library, there a few on github. A quick google brings: https://github.com/schwa/iOS-PDF-Reader and https://github.com/vfr/Reader

Upvotes: 1

Related Questions