need help to configure Maven dependencies for jasperrepot

 dependencies should i set to pom.xml for generate a PDF files ?

otmane-ch's picture
Joined: May 20 2014 - 6:42am
Last seen: 9 years 4 months ago

2 Answers:

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:



j.herrig's picture
Joined: May 20 2014 - 3:15am
Last seen: 6 years 1 month ago

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??

otmane-ch - 9 years 4 months ago

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).


j.herrig's picture
Joined: May 20 2014 - 3:15am
Last seen: 6 years 1 month ago

public void exporterPDF() throws JRException, IOException{
Map<String , Object> parameters = new HashMap<String,Object>();
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");
ServletOutputStream stream = response.getOutputStream();
JasperExportManager.exportReportToPdfStream(jasperPrint, stream);
System.err.println("pdf methode");


in JSF page :
<p:commandButton value="PDF"
actionListener="#{annonceController.exporterPDF}" />


this is just an example that i test ,but i dont get any PDF file after.

thank you for all

otmane-ch - 9 years 4 months ago

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.

j.herrig - 9 years 4 months ago

when i change to exportReportToPdfFile i see that a empty pdf file is genereted. :O

otmane-ch - 9 years 4 months ago
show 1 more...

... 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.

j.herrig - 9 years 4 months ago