Search in sources :

Example 1 with PrintPreviewReport

use of org.vaadin.reports.PrintPreviewReport in project komunumo-server by komunumo.

the class RegistrationsDialog method printRegistrations.

private void printRegistrations() {
    final var reportData = databaseService.getRegistrationsForAttendanceList(event.getId());
    final var registrationCount = reportData.size();
    for (var i = 0; i < 10; i++) {
        reportData.add(new RegistrationListEntityWrapper("", "____________________", "_______________"));
    }
    final var report = new PrintPreviewReport<>(RegistrationListEntityWrapper.class, "attendee", "city", "check");
    report.getReportBuilder().setTitle("%s: %s".formatted(formatDate(event.getDate().toLocalDate()), event.getTitle())).setSubtitle("%d registrations".formatted(registrationCount)).setDetailHeight(30).setColumnsPerPage(2, 10).getColumn(2).setWidth(15);
    final var websiteLogo = databaseService.configuration().getWebsiteLogo();
    if (!websiteLogo.isBlank()) {
        final var websiteLogoWidth = databaseService.configuration().getWebsiteLogoWidth();
        final var websiteLogoHeight = databaseService.configuration().getWebsiteLogoHeight();
        report.getReportBuilder().addFirstPageImageBanner(websiteLogo, websiteLogoWidth, websiteLogoHeight, ImageBanner.Alignment.Center);
    }
    final var resource = report.getStreamResource("registrations.pdf", () -> reportData, PrintPreviewReport.Format.PDF);
    final StreamRegistration registration = VaadinSession.getCurrent().getResourceRegistry().registerResource(resource);
    UI.getCurrent().getPage().open(registration.getResourceUri().toString());
}
Also used : StreamRegistration(com.vaadin.flow.server.StreamRegistration) PrintPreviewReport(org.vaadin.reports.PrintPreviewReport) RegistrationListEntityWrapper(org.komunumo.data.entity.reports.RegistrationListEntityWrapper)

Aggregations

StreamRegistration (com.vaadin.flow.server.StreamRegistration)1 RegistrationListEntityWrapper (org.komunumo.data.entity.reports.RegistrationListEntityWrapper)1 PrintPreviewReport (org.vaadin.reports.PrintPreviewReport)1