What are the steps in order to put a PDF into Xcode 7.2 and attach it to a button. I tried to follow various sources but they conflict with different ways. It is a pdf that I have and not from the internet. Would this be local or remote?
Asked
Active
Viewed 541 times
2 Answers
0
You can use a UIWebView to get the PDF from your bundle directly, no need to call an online web service.
Local File:
NSString *html = [NSString stringWithContentsOfFile:path1 encoding:NSUTF8StringEncoding error:nil];
[self.webView loadHTMLString:html baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]bundlePath]]];
for Remote File:
- (void) loadRemotePdf
{
CGRect rect = [[UIScreen mainScreen] bounds];
CGSize screenSize = rect.size;
UIWebView *myWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,screenSize.width,screenSize.height)];
webView.autoresizesSubviews = YES;
webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
NSURL *myUrl = [NSURL URLWithString:@"http://any url/test.pdf"];
NSURLRequest *myRequest = [NSURLRequest requestWithURL:myUrl];
[webView loadRequest:myRequest];
[window addSubview: myWebView];
[myWebView release];
}

Abhinandan Pratap
- 2,142
- 1
- 18
- 39
0
You can show pdf using UIwebview. IF file available on xcode then use this
NSString *path = [[NSBundle mainBundle] pathForResource:@"pdfName" ofType:@"pdf"]; NSURL *targetURL = [NSURL fileURLWithPath:path]; NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
and load this file on webview.
Same for if you pdf in remote(server) the you use that link to load on webview
NSURL *targetURL = [NSURL URLWithString:@"pdflink"]; NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
other you want PDF reader then here is a https://github.com/vfr/Reader

Bhuvan1690
- 12
- 4