2016-04-15 14 views
0

PDFをXcode 7.2に入れてボタンに添付するための手順は何ですか?私は様々な情報源に従おうとしましたが、さまざまな方法で矛盾しています。それは私が持っていてインターネットからではないpdfです。これはローカルかリモートか?PDFをXcodeに挿入するにはどうすればよいですか?

+0

可能な重複してほしい(http://stackoverflow.com/questions/10878744/how-to-display-pdf-on [iOSのPDFファイルを表示する方法] -ios) – Tibrogargan

答えて

0

UIWebViewを使用すると、バンドルから直接PDFを取得できます。オンラインWebサービスを呼び出す必要はありません。

ローカルファイル:リモートファイルのための

NSString *html = [NSString stringWithContentsOfFile:path1 encoding:NSUTF8StringEncoding error:nil]; 
[self.webView loadHTMLString:html baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]bundlePath]]]; 

- (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]; 

} 
0

あなたはのUIWebViewを使用してPDFを表示することができます。 xcodeで利用可能なIFファイル

NSString * path = [[NSBundle mainBundle] pathForResource:@ "pdfName" ofType:@ "pdf"]; NSURL * targetURL = [NSURL fileURLWithPath:path]; NSURLRequest * request = [NSURLRequest requestWithURL:targetURL];

このファイルをwebviewに読み込みます。あなたはWebViewの

NSURL *のTargetURL = [NSURL URLWithString: "pdflink" @]にロードするためにそのリンクを使用してリモート(サーバー)でPDFた場合のために同じ

。 NSURLRequest * request = [NSURLRequest requestWithURL:targetURL];

は、他のあなたは、PDFリーダーが、その後、ここでのhttps://github.com/vfr/Reader

関連する問題