dependencies should i set to pom.xml for generate a PDF files ?
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>
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).
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
when i change to exportReportToPdfFile i see that a empty pdf file is genereted. :O
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??