开发者

integrating PDF reader

How can I create a pdf reader in iphone? It should open within the same framework of my application. I have got cod开发者_高级运维e for creating PDF files but nothing for viewing a PDF. can anyone help me on dis ground?


You can use UIWebView or Quartz to display PDFs.

For UIWebView use this:

UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake( 0, 0, 320, 480 )];
NSString *path = [[NSBundle mainBundle] pathForResource:@"something" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
webView.scalesPageToFit = YES;
[self.view addSubview:webView];
[webView release];


I'm currently building an app that uses a PDF document as will. There are 2 way's to display a pdf document, by far the simplest (but slowest) way is using a UIWebView.

The other option is building some sort of reader yourself by using the quartz2d libraries.

Apple has some good documentation on it: quart2d programming guide.

And an Example called zooming PDF Viewer.


Avoid WebViews, they are slow and you have no control over them.

The best way to render PDFs on iOS is using the CGPDF* set of functions available with Quartz.

Be aware that it won't be super easy. Over time I have found and/or contributed to numerous questions on SO about PDFs on iPhone. Check those out:

Fast and Lean PDF Viewer for iPhone / iPad / iOs - tips and hints?

CGPDF iPhone/iPad memory problems

Get PDF hyperlinks on iOS with Quartz


I have created a PDF renderer here from apple's code. Just swipe left or right to browse through pages, pinch to zoom etc.

Here is my github.

Github PDF test

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜