gpt4 book ai didi

ios - 我们可以在 iOS 上使用 UIWebView 打开 pdf 文件吗?

转载 作者:IT王子 更新时间:2023-10-29 07:28:59 25 4
gpt4 key购买 nike

我们可以从 UIWebView 打开 pdf 文件吗?

最佳答案

是的,这可以通过 UIWebView 完成。

如果您尝试显示驻留在某处服务器上的 PDF 文件,您可以直接将其加载到您的 Web View 中:

objective-C

UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];

NSURL *targetURL = [NSURL URLWithString:@"https://www.example.com/document.pdf"];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];

[self.view addSubview:webView];

swift

let webView = UIWebView(frame: CGRect(x: 10, y: 10, width: 200, height: 200))

let targetURL = NSURL(string: "https://www.example.com/document.pdf")! // This value is force-unwrapped for the sake of a compact example, do not do this in your code
let request = NSURLRequest(URL: targetURL)
webView.loadRequest(request)

view.addSubview(webView)

或者,如果您的应用程序捆绑了一个 PDF 文件(在此示例中名为“document.pdf”):

objective-C

UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];

NSURL *targetURL = [[NSBundle mainBundle] URLForResource:@"document" withExtension:@"pdf"];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];

[self.view addSubview:webView];

swift

let webView = UIWebView(frame: CGRect(x: 10, y: 10, width: 200, height: 200))

let targetURL = NSBundle.mainBundle().URLForResource("document", withExtension: "pdf")! // This value is force-unwrapped for the sake of a compact example, do not do this in your code
let request = NSURLRequest(URL: targetURL)
webView.loadRequest(request)

view.addSubview(webView)

您可以在此处找到更多信息:Technical QA1630: Using UIWebView to display select document types .

关于ios - 我们可以在 iOS 上使用 UIWebView 打开 pdf 文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2832245/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com