Hey,
I would like to view a report as pdf first and then download.
For that, how can I create a button in details-view screen and clicking that button, I’ll have the report (created using report add-on) in a split screen using Pdf Viewer (Vaadin add-on).
Any code-snippet with necessary placement or a small project in zipped file will be appreciated.
N.B.: I’m using Jmix 2.3.3
@Subscribe("requirementDocDataGrid")
public void onRequirementDocDataGridItemClick(final ItemClickEvent<RequirementDoc> event) {
RequirementDoc selectedReqDoc = event.getItem();
// ProjectDoc has a property 'docImag' of type byte[]
byte[] pdfContent = selectedReqDoc.getDocImage();
PdfViewer pdfViewer = new PdfViewer();
StreamResource resource = new StreamResource(selectedReqDoc.getName(),
() -> new ByteArrayInputStream(pdfContent));
pdfViewer.setSrc(resource);
// Set the height to "100%" to occupy the full available vertical space
pdfViewer.setHeight("100%");
// Clear existing components in the filedisplay layout
filedisplay.removeAll();
// Add the PDF Viewer to the layout
filedisplay.add(pdfViewer);
// Set the height of the filedisplay VBox explicitly
filedisplay.setHeight("100%");
// Explicitly set margin and padding to zero
pdfViewer.getElement().getStyle().set("margin", "0").set("padding", "0");
filedisplay.getElement().getStyle().set("margin", "0").set("padding", "0");
}
I’ve already implemented this for loading any pdf from the database. But when I have a report generated by a service bean, is there any way to have a pdf version of that report which can be viewed in a screen apart from direct download?