如何在 Vaadin Flow 上打开生成的文件?

How to open a generated file on Vaadin Flow?

在我的应用程序上,我想在新选项卡上使用 PdfBox 打开生成的 PDF,我看过一些文档,但它们适用于旧版本的 Vaadin,或者不适用于我的情况。我不想将它保存在服务器上或将文件附加到任何 link 或按钮,我想编写一个方法在新选项卡上自动打开它。

PdfBox 提供了将文件保存到 OutputStream 的选项,有什么方法可以在新选项卡上打开该 OutputStream 文件吗?或者至少下载它而不像 Flow Viritin 那样将它附加到 Anchor 小部件?

问题在于因为你不想将文件保存在服务器上,所以你不能直接将url的所述文件直接link到。您也不能将 pdf 文件作为参数传递给另一个视图。

解决方法是 (as byte[] is probably easiest), and when the user then opens another tab by clicking a certain anchor/routerlink, that view will read the pdf from the VaadinSession and add the it to the view. (How to display pdf with Vaadin 14)。请记住再次从 VaadinSession 中删除 pdf :)