The Requirement is to open a PDF file from a jsp without any redirection in single click using Ajax POST.
JSP -> AJAX Post Call -> Server Code returning Response to Ajax -> Print the PDF with the returned data
Ajax Code:
- Code: Select all
$.ajax({
type: "POST",
url: "/PrintDocument/PrintServlet?type=pdf",
data: 'htmlContent='+ escape(someDataToServlet),
success: function(data){
alert(data);
// To-do block to oepn the PDF
},
error:function (data){
}
});
Servlet Code:
- Code: Select all
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setWmlPackage(wordMLPackage);
Docx4J.toFO(foSettings, response.getOutputStream(), Docx4J.FLAG_NONE);
I'm getting data in the alert or page like below
%PDF-1.4 %ª«¬ 4 0 obj << /Creator (Apache FOP Version 1.0) /Producer (Apache FOP Version 1.0) /CreationDate (D:20140303114827+05'30') >> endobj 5 0 obj << /N 3 /Length 14 0 R /Filter /FlateDecode >> stream xœ–wTSهϽ7½P’Š”ÐkhRH ½H‘.*1 JÀ"6DTpDQ‘¦2(à€£C‘±"Š…Q±ëDÔqp–Idß¼yïÍ›ß÷~kŸ½ÏÝgï}ÖºüƒÂLX € ¡Xáçň‹g` ðlàp³³BøF™|ØŒl™ø½º ùû*Ó?ŒÁÿŸ”¹Y"1P˜ŒçòøÙ\É8=Wœ%
PDF is opening fine if it is URL ajax call.
Please help me in getting the PDF open using ajax-post.
Thanks in advance.
Regards,
Praveen J