PDA

View Full Version : pdf download dialog window not appear in browser.



rushi2440
21 Jan 2012, 12:25 AM
Hi.. sencha forum member i am little bit confuse in my report export process. I am able to generate the report in pdf form using jasper report and java.

The report generated not available to be get download to the client side.
I am generating pdf file using below code


public void getTaskreportPDF(Session openSession,HttpServletRequest request,
HttpServletResponse response) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/contact","root","root");

Map params = getParameters(openSession);
Date date = new Date();
String reportfileName = "report"+date.getDate()+"-"+date.getMonth()+"-"+date.getYear()+"-"+date.getTime()+".pdf";
JasperDesign jasperDesign = JRXmlLoader.load(this.getClass().getResourceAsStream("/com/gantt/report/ganttreport.jrxml"));
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);

JasperPrint jasperprint = JasperFillManager.fillReport(jasperReport, params,con);

JRAbstractExporter exporterPDF = new JRPdfExporter();
exporterPDF.setParameter(JRExporterParameter.JASPER_PRINT, jasperprint);
exporterPDF.setParameter(JRExporterParameter.OUTPUT_STREAM, response.getOutputStream());
response.setHeader("Content-Disposition", "inline;filename="+ reportfileName);
response.setContentType("application/pdf");
exporterPDF.exportReport();
} catch(Exception exception) {
System.out.println("Error occured " +exception.getMessage());
}
}


when i view my firebug net tab i am getting response as

Response Headersview source

Content-Disposition
inline;filename=report21-0-112-1327133892240.pdf


Content-Type
application/pdf


Date
Sat, 21 Jan 2012 08:18:18 GMT


Server
Apache-Coyote/1.1


Transfer-Encoding
chunked


Request Headersview source


Accept
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8


Accept-Charset
ISO-8859-1,utf-8;q=0.7,*;q=0.7


Accept-Encoding
gzip, deflate


Accept-Language
en-us,en;q=0.5


Connection
keep-alive


Cookie
JSESSIONID=61B442502AEF0B8F445E4FC048FE9478; bmeval=1327129699647


Host
localhost:8085


Referer
http://localhost:8085/Gantt/


User-Agent
Mozilla/5.0 (Windows NT 6.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1




Request Headers From Upload Stream


Content-Length
45


Content-Type
multipart/form-data; boundary=---------------------------181274673728




my response is correct and i am getting the pdf file having size of 4 kb. but the problem is that the download dialog window is not available. so help me to find my problem so I can solve it.

my app.js is


Ext.onReady(function() {
Ext.QuickTips.init();

App.init();
});


TaskPriority = {
Low : 0,
Normal : 1,
High : 2
};


App = {


// Initialize application
init: function () {

//create the downloadframe at the init of your app
this.downloadFrame = Ext.getBody().createChild({
tag: 'iframe'
, cls: 'x-hidden'
, id: 'iframe'
, name: 'iframe'
});
//create the downloadform at the init of your app


this.downloadForm = Ext.getBody().createChild({
tag: 'form'
, cls: 'x-hidden'
, id: 'form'
, target: 'iframe'
});


var params = new Object();

var g = Ext.create("Gnt.panel.Gantt", {
height: '100%',
width: '99%',
renderTo: Ext.getBody(),
leftLabelField: 'Name',
loadMask: true,
startDate: start,
endDate: end,
multiSelect : true,
cascadeChanges : true,
viewPreset: 'weekAndDayLetter',
recalculateParents: false,

tbar: [{
iconCls : 'icon-pdf',
scale : 'large',
text : 'Export to PDF',
handler : function(button, event){
//code goes here
Ext.Ajax.request({
url: 'task/GetTaskReportPDF.action',
params: params,
form: App.downloadForm,
isUpload: true,
// method: 'POST',
success : function(response, option){
//this.gestioneRisposta(response);
console.log("success");
}
,failure :function(response, option){
console.log("failure");
}
,scope : this
});
}
}
]
});
}
};


I am using Java as my server side technology and for the report i am using Jasper Report.

Yogendra Singh
Sr. Programmer
Kintudesigns.com

rushi2440
21 Jan 2012, 2:01 AM
hi.. forum member.

I am able to get my download window that download the pdf file for me. But the problem is that the file name always comes as GetTaskReportPDF.action

I tried to use exporterPDF.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, reportfileName); to give my file name but that also doesn't work.

I got my solution by removing the inline from the header.


Yogendra Singh

Sr. Programmer

Kintudesigns.com

rushi2440
21 Jan 2012, 2:07 AM
got a solution by changing the response header as

response.setHeader("Content-disposition",
"attachment; filename=\"" +"example.pdf" +"\"");

thanks for your support forum members.


Yogendra Singh

Sr. Programmer

Kintudesigns.com

Animal
21 Jan 2012, 5:24 AM
Why not just use a Button with an href config?

tvanzoelen
23 Jan 2012, 12:12 AM
@Animal, maybe because sending params is the problem in that case. Otherwise I think thats a nice solution, less code.