如何在UIWebview中心加载pdf文件 [英] how to load pdf file in UIWebview center

查看:160
本文介绍了如何在UIWebview中心加载pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ios开发的新手.我试图在UIWebview中心中显示pdf.我在mainbundle中有一个pdf.这是现在加载到UIWebView中时我的PDF的样子:作为UIWebView的背景,这样您就可以更好地理解我的意思了.

I am new in ios developement.I am trying to display a pdf in a UIWebview center.i have a pdf in mainbundle.Here is what my PDF looks like now when loaded in a UIWebView: (I put in a brown gradient as the UIWebView's background so you can see what I mean better).

- (void)viewDidLoad
{
UIWebView *theWebView = [[UIWebView alloc] initWithFrame:[self.view bounds]];
[theWebView setContentMode:UIViewContentModeScaleAspectFit];
[theWebView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];
[theWebView setScalesPageToFit:YES];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"pdf"];
NSURL *filePathURL = [NSURL fileURLWithPath:filePath];
[theWebView loadRequest:[NSURLRequest requestWithURL:filePathURL]];

[self.view addSubview:theWebView];
[super viewDidLoad];
}

我想居中,以使下边距与上边距相同.我将如何使用PDF(本地)进行此操作?

I would like to centre that so that the bottom margin is the same as the top margin. How would I do this with a PDF (local)?

推荐答案

CGRect rect = [[UIScreen mainScreen] bounds];
    CGSize screenSize = rect.size;
    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,screenSize.width,screenSize.height)];

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

    [self.view addSubview:webView];

这篇关于如何在UIWebview中心加载pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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