from projName.settings import BASE_DIR
from subprocess import Popen, PIPE, STDOUT
from wsgiref.util import FileWrapper
from django.http import StreamingHttpResponse
class DownloadAsPDF(View):
def post(self, request, *args, **kwargs):
base = str(BASE_DIR)
file_name = str( base + '/testreport.pdf')
post_url = request.POST.get("page_url")
url = str('http://' + request.get_host() + post_url)
chrome_args = ['/path/google-chrome', '--headless', '--virtual-time-buget=20000',
'--print-to-pdf=/path/testreport.pdf', url]
external_process = Popen(chrome_args, stdout=PIPE, stderr=STDOUT)
external_process.wait()
return_file = FileWrapper(open('{}'.format(file_name), 'r'))
download_file_name = 'report'
response = StreamingHttpResponse(return_file, content_type='application/force-download')
response['Content-Disposition'] = f'attachment; filename= {download_file_name}.pdf'
return response
Can please anybody, tell me why is it generating this error and what is the possible solution
this problem,
Thanks you very much