Closed florianrhomberg closed 2 years ago
I could solve the problem, it seems to be the same "issue" as already mentioned that the Plugin is not working directly with stream resources (I think the problem ist that the Stream resource returns only the dynamic part of the URL, but not the complete one). The following code is working and the PDFViewer displays sucessfully the PDF:
FileRecord file;
//
// This is a workaround to use the PDFViewer, which only works with complete URLs.
//
String requestUrl = ((VaadinServletRequest) VaadinService.getCurrentRequest()).getRequestURL().toString();
if(!requestUrl.endsWith("/"))
requestUrl = requestUrl+"/";
StreamResource resource = StreamResourceHandler.getStream(record);
final StreamRegistration registration = VaadinSession.getCurrent().getResourceRegistry().registerResource(resource);
this.url = requestUrl+registration.getResourceUri().toString();
PdfViewer viewer = new PdfViewer();
viewer.setSrc(url);
viewer.setSizeFull();
this.add(viewer);
I hope that it helps some people who have the same problem. Florian
Hello, with Vaadin 22.0.4 I get the above mentioned error when trying to open a PDF with the pdf Viewer, resulting that the PDF is not displayed, however downloading is working fine:
Has someone the same problem?
Florian