How to create PDF from .jasper

0

I created a report in iReports and generated the .jasper, but I have no idea how to generate the PDF, I've tried several tutorials and nothing works to create the pdf. What I need is to generate the PDF and pick up the path of the created file to be inside a field in the database. I was trying to use this method, it does not return any errors, but it also does not create the file.

   public void imprimirRelatorio() throws IOException, ParseException {

        HashMap parametros = new HashMap();
        parametros.put("ID_EDITAL", 28);

        FacesContext facesContext = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();

        response.setContentType("application/pdf");

        response.setHeader("Content-disposition",
                "inline; filename=\"arquivo.pdf\"");
        try {
            JRBeanCollectionDataSource dsColecao = new JRBeanCollectionDataSource(lista, false);
            JasperPrint impressoraJasper = JasperFillManager.fillReport("d:/Edital.jasper", parametros, dsColecao);
            ServletOutputStream streamDeSaida = response.getOutputStream();
            JasperExportManager.exportReportToPdfStream(impressoraJasper,
                    streamDeSaida);
        } catch (JRException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        facesContext.responseComplete();    
    }
}

Where do I call the method:

                    <p:commandButton value="Submit"
                        actionListener="#{editalBean.inserirEdital}" update="growl"
                        process="@this" />

When calling the editalBeanEdit method of editalBean, it invokes the method printReport ().

The list I pass in the dataSource in this case is a list of Edits. Could someone help me? Set a course? I'm totally lost.

    
asked by anonymous 31.01.2015 / 17:26

0 answers