1

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

1 Answers1

0

Try this. I'm on my 5th margarita. It should work. :) Remember to add route for "download_PDF".

@view_config(route_name="download_PDF", renderer="")
 def download_view(request):
     filepath = ("pathtomyfile/test.pdf")
     response = FileResponse(filepath)
     response.headers['Content-Disposition'] = ("attachment; filename=test.pdf")
     return response

Whoops. This just downloads the file. Maybe you can make it work with jinja. Again. too many margaritas: )

fat fantasma
  • 7,483
  • 15
  • 48
  • 66