Jump to content

Recommended Posts

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

Posted

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>

 

 

Posted

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

Posted

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

 

Posted

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

 

Posted

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.

Posted

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...