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

 

 

j.herrig's picture
192
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
192
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>();
//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 :
<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
Feedback
randomness