class GenerateInvoiceView(APIView):
def get(self, request, format=None):
# pdf_file = open(g.get_path(user_id), 'rb')
html_template = render_to_string('pdf_templates/invoice.html', {'foo': 'bar'})
# print(html_template)
pdf_file = HTML(string=html_template).write_pdf()
response = HttpResponse(pdf_file, content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename=ordersummary.pdf'
# os.unlink(pdf_file.name)
# print(pdf_file.name)
return response
downloadReport(markentryid, student) {
return this.httpClient.get('/reports/downloadreport/', {
params: {markentryid: markentryid, student: student},
headers: new HttpHeaders().append('Content-Type', 'application/pdf'),
responseType: 'blob',
observe: 'body'
});
}
downloadPdf() {
this.studentreportsService.downloadReport(this.id, this.studentid)
.subscribe(
res => {
// http://jslim.net/blog/2018/03/13/Angular-4-download-file-from-server-via-http/
console.log('start download:', res);
const url = window.URL.createObjectURL(res);
const a = document.createElement('a');
document.body.appendChild(a);
a.setAttribute('style', 'display: none');
a.href = url;
a.download = 'progress_report.pdf';
a.click();
window.URL.revokeObjectURL(url);
a.remove(); // remove the element
}, error => {
console.log('download error:', JSON.stringify(error));
}, () => {
console.log('Completed file download.');
}
);
}