如何控制在UIWebView for iOS中加载的页面显示为PDF(转到页面) [英] How to control page display to PDF loaded in UIWebView for iOS (go to page)

查看:458
本文介绍了如何控制在UIWebView for iOS中加载的页面显示为PDF(转到页面)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,它显示嵌入在WebView中的PDF,这是我的代码:

I'm developing an app which displays a PDF embedded in a WebView this is my code:

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSURL *urlremoto = [NSURL URLWithString:@"https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/TransitionGuide.pdf"];

    request = [NSURLRequest requestWithURL:urlremoto];

    [self.webView loadRequest:request];
    [self.webView setScalesPageToFit:YES];
}

-(void)webViewDidStartLoad:(UIWebView *)webView{

    [self.activityIndicator startAnimating];
}

-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    //TODO: describir el error
    [self.activityIndicator stopAnimating];        
}

-(void)webViewDidFinishLoad:(UIWebView *)webView{

    [self.activityIndicator stopAnimating];
}

现在我想触摸一个按钮,将我加载的PDF更改为某个页面,我正在寻找能够实现这一目标的东西,但仍然无法正常工作

Now I want to touch a button and change my loaded PDF to certain page, I'm looking for something to achieve this but still got nothing working

提前感谢支持

推荐答案

此时我认为你可以使用两种方法:

At this moment I think you can use two approaches:


  1. 使用scrollView来'导航,通过PDF:

  1. Use scrollView to 'navigate, through PDF:

[[webView scrollView] setContentOffset:CGPointMake(0,y)animated:YES];

[[webView scrollView] setContentOffset:CGPointMake(0,y) animated:YES];

//例如,跳转到页面高度为1000像素的PDF文档中的第5页:

// For example, jumping to page 5 in a PDF document with 1000 px page height:

int selectedPag = 5; // i.e. Go to page 5

float pageHeight = 1000.0; // i.e. Height of PDF page = 1000 px;

float y = pageHeight * selectedPag;

[[webView scrollView] setContentOffset:CGPointMake(0,y) animated:YES];


  • 拆分PDF单页。

  • Split PDF individual pages.

    这篇关于如何控制在UIWebView for iOS中加载的页面显示为PDF(转到页面)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆