我正在尝试在 vaadin 中生成 pdf。我的问题是生成的 pdf 在当前窗口(浏览器选项卡)中打开。我试过了:
String filename = contentDataName + ".pdf";
StreamResource resource = new StreamResource(source, filename, vaadinApplication);
resource.getStream().setContentType("application/pdf");
resource.getStream().setFileName(filename);
resource.getStream().setParameter("Content-Disposition", "attachment; filename=\"" + filename + "\"");
resource.getStream().setParameter("Content-Length", Integer.toString(fopOutput.size()));
resource.setCacheTime(5000);
resource.setMIMEType("application/pdf");
mainWindow.open(resource);
mainWindow.open(resource, "_blank", true);
它不起作用。我错过了什么?我也试过
mainWindow.open(resource, "_blank");