Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
Version: Windchill 12.0
Use Case: We have a custom action where when the user clicks on it, a jasper report is downloaded as pdf in the background
Description:
Hello all,
I am trying to run a Jasper Report from java code. I have few questions regarding that-
1. I have a jrxml with multiple data sources( infoengine tasks), how do I combine all of them into one Jasper Print object using the below API?
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters);
2. When exporting the jasper report as pdf, how can I give the path so that the report gets automatically downloaded in the user's local system? Currently I am running the report on the server so the pdf is saved in the server location itself, so how can I change that? Below, instead of creating the LfDocumentReport.pdf in the particular location, it creates a pdf in appl/ptc/Windchill_12.0/Windchill location with the whole name given as path
JasperExportManager.exportReportToPdfFile(jasperPrint, "C:\\Users\\55806@itcinfotech.com\\Downloads\\LfDocumentReport.pdf");
I have attached the code in this post. Any help or suggestions would be helpful
Thankyou,
Ramsha Kamal
Hi @RK_10805837
If you want to download the file locally to a client you need to work with a HTTP request and return a response with the downloading file.
PetrH
Hi @HelesicPetr ,
Thanks for your reply. I am downloading the pdf in the backend so when I try to pass HTTP request, it returns null and throws NullPointerException. Can you please elaborate on how to do that? Also, can you please give some hint for the first part of the question? How to combine multiple data sources to create Jasper Print object?
Hi @RK_10805837
It is common method.
// HTTPResponse response, byte[] byteArray,String downloadfileName
response.setHeader("Content-Disposition", "attachment; filename=\"" + downloadfileName + "\"");
OutputStream os = response.getOutputStream();
os.write(byteArray);
os.flush();
PetrH
Did you try using HttpResponse class to send the pdf to the user? I have used this many times to send pdf files to the user that initiates a custom action.
Hi @RK_10805837,
I wanted to see if you got the help you needed.
If so, please mark the appropriate reply as the Accepted Solution. It will help other members who may have the same question.
Please note that industry experts also review the replies and may eventually accept one of them as solution on your behalf.
Of course, if you have more to share on your issue, please pursue the conversation.
Thanks,