Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @SuppressWarnings({ "static-access", "serial", "rawtypes" })
- public static void printPgReport(final String reportName, final Map parameter) {
- emPg.getEntityManager().getTransaction().begin();
- final java.sql.Connection conn = emPg.getEntityManager().unwrap(java.sql.Connection.class);
- emPg.getEntityManager().getTransaction().commit();
- if (conn == null) {
- System.out.println("Error de conexion...\n");
- return;
- }
- StreamResource.StreamSource source = null;
- try {
- source = new StreamResource.StreamSource() {
- @SuppressWarnings("unchecked")
- public InputStream getStream() {
- byte[] b = null;
- try {
- InputStream rep = getClass().getClassLoader().getResourceAsStream("/edu/ceac/app/reportes/"+reportName+".jasper");
- System.out.println(rep);
- if (rep != null) {
- parameter.put("IMAGE_PATH", "/edu/ceac/app/reportes/images/");
- parameter.put("SUBREPORT_PATH", "/edu/ceac/app/reportes/subreportes/");
- JasperReport report = (JasperReport) JRLoader.loadObject(rep);
- b = JasperRunManager.runReportToPdf(report, parameter, conn);
- System.out.println(Paths.get(".").toAbsolutePath().normalize().toString());;
- JasperPrint print = JasperFillManager.fillReport(report, parameter, conn);
- JasperExportManager.exportReportToPdfFile(print, Paths.get(".").toAbsolutePath().normalize().toString()+"/reportName.pdf");
- } else {
- Notification.show("Atención!!!", "No se encontró el reporte...", Type.WARNING_MESSAGE);
- }
- } catch (JRException e) {
- System.out.println("Error:\n");
- e.printStackTrace();
- }
- return new ByteArrayInputStream(b);
- }
- };
- } catch(Exception e) {
- Notification.show("Atención!!!", "Ocurrió un problema al generar el archivo...", Type.WARNING_MESSAGE);
- }
- StreamResource resource = null;
- try {
- resource = new StreamResource(source, reportName + "_" + System.currentTimeMillis() + ".pdf");
- } catch (Exception e) {
- System.out.println("Error:\n");
- e.printStackTrace();
- return;
- }
- Window window = new Window();
- window.setWidth(70, Unit.PERCENTAGE);
- window.setHeight(90, Unit.PERCENTAGE);
- BrowserFrame extF = new BrowserFrame("PDF File", resource);
- extF.setWidth("100%");
- extF.setHeight("100%");
- window.setContent(extF);
- window.center();
- window.setModal(true);
- UI.getCurrent().addWindow(window);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement