user3245747
user3245747

Reputation: 937

Saving jasper report as pdf on server

I have a servlet that uses jasper reports to create a pdf. This pdf is displayed in the web browser using the JasperExportManager.exportReportToPdfStream() method. This works fine. However, what I want is to save the file in a folder that resides on the server. I have tried to do this with the following code:

String outputFile = getServletContext().getRealPath("/theFolder");
JasperExportManager.exportReportToPdfFile(jasperPrint, outputFile + "/thePDF.pdf");

This code does not produce any errors and runs to completion, but I can't find the file anywhere on the server. What am I doing wrong? Thanks.

Upvotes: 2

Views: 7218

Answers (3)

Liz Romero
Liz Romero

Reputation: 1

I have the same code, and the PDF is saved in: C:\Users\weblogic\AppData\Roaming\JDeveloper\system11.1.1.3.37.56.60\o.j2ee\drs\YOUR PROJECT\ViewControllerWebApp.war\YOUR FOLDER

Upvotes: 0

Anuja
Anuja

Reputation: 419

If your jasper debug logs are configured well. In the output you will see the path where your report is getting generated.

OR you can use my code

String path=System.getProperty("user.dir");
JasperExportManager.exportReportToPdfFile(this.jp, path + "/reports/Report.pdf");

This will save your file where you want relative to the path of the folder. You can also provide absolute path if necessary.

Also check if the report is present in the target folder of your Project.

Upvotes: 3

Vivek Giri
Vivek Giri

Reputation: 485

Try this 
JRExporter exporter = new JRPdfExporter();

/*
* Saves the PDF file generated inside 
* ....../build/web/WEB-INF/resources/invoice/filename.pdf
*/
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, outputFile);
exporter.exportReport();

Upvotes: 0

Related Questions