在 Vaadin 视图中显示 PDF [英] Show PDF in a Vaadin View

查看:29
本文介绍了在 Vaadin 视图中显示 PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Vaadin 视图中显示 PDF.我创建了一个 BrowserFrame 并传递了 PDF 的 StreamResource:

I want to show a PDF in a Vaadin view. I create a BrowserFrame and I pass the StreamResource of the PDF:

StreamResource streamResource = new StreamResource(
                getPresenter().createPdfStreamSource(), report.getName() + ".pdf");


BrowserFrame pdf = new BrowserFrame(null, streamResource);
pdf.setSizeFull();

content.addComponent(pdf);

此代码使用以下来源创建 iframe:

This code creates an iframe with the following source:

http://localhost:8080/my-app/vaadinServlet/APP/connector/0/134/source/mypdf.pdf

如果我将浏览器指向此 URL,它会正确显示 PDF.但是在我的应用程序中,PDF 视图没有显示.我究竟做错了什么?

If I point the browser to this URL, it shows the PDF properly. However in my application the PDF view doesn't show. What am I doing wrong?

我正在 Google Chrome 中对此进行测试.

I am testing this in Google Chrome.

编辑:我下载了基于 PDF.js 的插件 PDF 查看器,我的应用程序运行良好.Chrome PDF 阅读器插件需要特殊配置吗?

Edit: I downloaded the plugin PDF Viewer based on PDF.js and my app works fine. Does the Chrome PDF reader plugin need special configuration?

推荐答案

iframe 可能不是呈现 PDF 的最佳选择,尤其是在移动浏览器上.检查基于 pdf.js 的 WT PDF Viewer 附加组件更兼容的解决方案.

An iframe is probably not the best option to render a PDF, especially on mobile browsers. Check the WT PDF Viewer add-on which is based on pdf.js for a more compatible solution.

这篇关于在 Vaadin 视图中显示 PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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