how to send PDF file that can be rendered to jinja2?? write both codes (.py) and (.js) if possible. here is my ajax code
$("#print").click(function(event) {
$.ajax(
{
type: "POST",
url: "/printledgerreport",
global: false,
async: false,
dataType : 'json',
//contentType : 'application/pdf'
data: {"backflag":0,"accountcode":$("#accountcode").val(),"calculatefrom":$("#calculatefrom").val(), "calculateto":$("#calculateto").val(),"financialstart":sessionStorage.yyyymmddyear1,"projectcode":$("#projectcode").val(),"monthlyflag":false,"narrationflag":false},
beforeSend: function(xhr)
{
xhr.setRequestHeader('gktoken',sessionStorage.gktoken );
},
success: function(data){
window.open("ledgerReport.pdf");
}
});
});
please tell me how to write pyramid code
Now here is my new pyramid code:
@view_config(route_name="printledgerreport", renderer="")
def printLedgerReport(request):
filepath = ("ledgerReport.pdf")
response = FileResponse(filepath)
response.headers['Content-Disposition'] = ("attachment; filename=ledgerReport.pdf")
return response