PDF 在 UIWebView 中无法正确显示

发布于 2024-10-25 22:47:24 字数 1427 浏览 0 评论 0原文

我有一个 UIWebView,我想在其中显示 PDF 文件。 PDF 文件位于远程网络服务器上,因此像任何其他 URL 一样加载。

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.findsmiley.fvst.dk/KontrolRapport.aspx?id=20328832&akt=1"]]];

但 PDF 无法正确显示。我无法滚动或缩放文档。 在控制台中,我收到以下错误代码(当然,CafeHelmuth 是我的应用程序的名称)

Wed Mar 23 15:56:31 simonbs-macbook CafeHelmuth[1997] <Error>: 
Wed Mar 23 15:56:31 simonbs-macbook CafeHelmuth[1997] <Error>: 
Wed Mar 23 15:56:31 simonbs-macbook CafeHelmuth[1997] <Error>: 
Wed Mar 23 15:56:31 simonbs-macbook CafeHelmuth[1997] <Error>: 
Wed Mar 23 15:56:31 simonbs-macbook CafeHelmuth[1997] <Error>: 
Wed Mar 23 15:56:31 simonbs-macbook CafeHelmuth[1997] <Error>: 
Wed Mar 23 15:56:31 simonbs-macbook CafeHelmuth[1997] <Error>: 
Wed Mar 23 15:56:31 simonbs-macbook CafeHelmuth[1997] <Error>: 
Terminating in response to SpringBoard's termination.
Program ended with exit code: 0

在下图中,您会看到它不会滚动网页,而是滚动视图,当然, ,是错误的。

谁能帮助我让我的网络视图正确显示 PDF 文档?

UIWebView 不滚动网页

loadRequestwebView.scalesPageToFit = YES; > 使它看起来有点奇怪,虽然它确实添加了缩放和滚动,但它似乎不是正确的方法。下面是一些这样的图像。

缩小时

当我放大时,背景变成蓝色,并且.. 嗯,看起来很奇怪。

放大时

I have a UIWebView in which I want to display a PDF file. The PDF file is located on a remote webserver and is therefore loaded like any other URL.

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.findsmiley.fvst.dk/KontrolRapport.aspx?id=20328832&akt=1"]]];

The PDF is not displayed correctly, though. I am not able to scroll or zoom the document.
In the console I get the following error codes (CafeHelmuth being the name of my application, of course)

Wed Mar 23 15:56:31 simonbs-macbook CafeHelmuth[1997] <Error>: 
Wed Mar 23 15:56:31 simonbs-macbook CafeHelmuth[1997] <Error>: 
Wed Mar 23 15:56:31 simonbs-macbook CafeHelmuth[1997] <Error>: 
Wed Mar 23 15:56:31 simonbs-macbook CafeHelmuth[1997] <Error>: 
Wed Mar 23 15:56:31 simonbs-macbook CafeHelmuth[1997] <Error>: 
Wed Mar 23 15:56:31 simonbs-macbook CafeHelmuth[1997] <Error>: 
Wed Mar 23 15:56:31 simonbs-macbook CafeHelmuth[1997] <Error>: 
Wed Mar 23 15:56:31 simonbs-macbook CafeHelmuth[1997] <Error>: 
Terminating in response to SpringBoard's termination.
Program ended with exit code: 0

On the image below you see that it does not scroll the web page but the view, which, of course, is wrong.

Can anyone please help me make my web view display the PDF document correctly?

UIWebView not scroll webpage

Adding webView.scalesPageToFit = YES; before loadRequest makes it look a bit strange, though it does add zoom and scroll but it does not seem to be the right approach. Beneath are some images of this.

When zoomed out

When I zoom in the background becomes blue and.. Well, it looks strange.

When zoomed in

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怼怹恏 2024-11-01 22:47:25

添加一行

webView.scalesPageToFit = YES;

在 loadRequest 行之前

Add a line

webView.scalesPageToFit = YES;

before the loadRequest line

寄居人 2024-11-01 22:47:25

我没有找到任何解决方案来自定义网络视图的行为。但我已经为您的 pdf 找到了解决方案:将 pdf 格式更改为 10.7 厘米 x 15.7 厘米。看一下这个示例: webview 中的 pdf 示例

I didn't find any solution to customize the behaviour of the webview. But I have found a solution for your pdf: Change the pdf's format to 10.7 cm x 15.7 cm. Have a look at this example: pdf example in webview

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文