otmane-ch Posted May 20, 2014 Posted May 20, 2014 dependencies should i set to pom.xml for generate a PDF files ?
j.herrig Posted May 21, 2014 Posted May 21, 2014 I did have a lot of trouble when trying the same ....At the moment the following is my personal configuration. You can use it for a initial try:<dependency> <groupId>net.sf.jasperreports</groupId> <artifactId>jasperreports</artifactId> <version>5.5.1</version> </dependency> <dependency> <groupId>com.lowagie</groupId> <artifactId>itext</artifactId> <version>2.1.7</version> <scope>compile</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> </dependency> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> <version>2.0.1</version> <scope>compile</scope> <optional>true</optional> </dependency>
otmane-ch Posted May 21, 2014 Author Posted May 21, 2014 thank you for your answer @j.herrig but ,when i click to genreate no thing is happend & no error is displayed i dont know what's wrong in my code. in your case you didn't add dependency for itext??
j.herrig Posted May 21, 2014 Posted May 21, 2014 The second dependency is indeed for itext ;-) .... all 4 dependencies I listed here I need for generate pdf ...If you still have problems ... give us more information how you are working (example of your code).
otmane-ch Posted May 21, 2014 Author Posted May 21, 2014 public void exporterPDF() throws JRException, IOException{ Map parameters = new HashMap(); //System.out.println("********************************"+societe.getActe().getDateActe()); parameters.put("DateActe", new Date()); File jasper = new File(FacesContext.getCurrentInstance().getExternalContext().getRealPath("/report1.jasper")); JasperPrint jasperPrint = JasperFillManager.fillReport(jasper.getPath(), parameters,new JRBeanCollectionDataSource(this.getIntervenants())); HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse(); response.addHeader("Content-disposition", "attachement; filename = annonce.pdf"); response.setContentType("application/pdf"); ServletOutputStream stream = response.getOutputStream(); JasperExportManager.exportReportToPdfStream(jasperPrint, stream); stream.flush(); stream.close(); FacesContext.getCurrentInstance().responseComplete(); System.err.println("pdf methode"); } ///////////////////////////////////////////////// in JSF page : actionListener="#{annonceController.exporterPDF}" /> ////////////////////////////////////// this is just an example that i test ,but i dont get any PDF file after. /////////////////////////////// thank you for all
j.herrig Posted May 22, 2014 Posted May 22, 2014 Your example seems to be a good way to do a first try. I have following remarks to help to locate you problem: 1. when you debug through exportPDF()is jasperPrint object available as expected? If yes, just try to write the pdf to the file system using JasperExportManager.exportReportToPdfFile(jasperPrint, "C:/yourPdf.pdf"); Then open it by pdf-reader .... 2. exportPDF() thows Exception. Where do you log it. Really no messages there? 3. assuming your maven build is runing without problems.
otmane-ch Posted May 22, 2014 Author Posted May 22, 2014 when i change to exportReportToPdfFile i see that a empty pdf file is genereted. :O
j.herrig Posted May 23, 2014 Posted May 23, 2014 ... one step futher ... ;-) Now create a report only containing static data. E.g. label with text. Then try to generate a pdf from it. When this works you did something wrong with your datasource.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now