Description
Hi, I'm experiencing an issue with the PdfViewer:
When printing in Firefox, a blank or incorrect document is displayed. The PDF is displayed correctly in the PdfViewer itself, but when the print button is pressed, the print preview opens and shows it as blank, so that it cannot be printed. Other browsers like Chrome or Edge do not have this problem.
Through debugging, I can confirm that the uri and src in the PdfViewer are correctly passed, and the download also works. The correct src is transmitted for printing, but the document remains blank. I'm using Vaadin 23 and PdfViewer 2.7.4.
A similar issue has been reported before, with a suggested solution. I've implemented this in my code, but it hasn't resolved the the problem for me. Print buton does not work (print.js error)
Here are the code snippets:
StreamResource resource = new StreamResource("Name" + ".pdf",
() -> new ByteArrayInputStream(byteArrayOutputStream.toByteArray())
);
verticalLayoutPDFView.removeAll();
verticalLayoutPDFView.add(PdfViewerHelper.pdfViewer(resource));
public static PdfViewer pdfViewer(StreamResource resource) {
PdfViewer pdfViewer = new PdfViewer();
pdfViewer.setAddPrintButton(true);
pdfViewer.setAutoZoomOptionLabel("Autom. Zoom");
pdfViewer.setPageFitZoomOptionLabel("Ganze Seite");
String contextPath = VaadinRequest.getCurrent().getContextPath();
StreamRegistration streamRegistration = VaadinSession.getCurrent().getResourceRegistry().registerResource(resource);
String uri = contextPath + "/" + streamRegistration.getResourceUri();
pdfViewer.setSrc(uri);
pdfViewer.setHeightFull();
return pdfViewer;
}