Hello Django Family, I hope you all are well and in good Health.

I am trying to generating pdf from webpages, using popen subprocess , but
when i call its

view it generates only login page as pdf,


Here is my view


from projName.settings import BASE_DIR

from subprocess import Popen, PIPE, STDOUT

from wsgiref.util import FileWrapper



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 = FileResponse(return_file,
content_type='application/force-download')

response['Content-Disposition'] = f'attachment; filename=
{download_file_name}.pdf'

return response


I was thinking of creating the popen subprocess in the same browser session
so that it will directly go to the said url page, instead of login page,

I couldn't find any good resources to implement this functionality, as it
is headless chrome here may be it's not possible to open in the same
browser session.


If this can't be the perfect solution, then please if anyone have some
other solution I will be very thankful,

Thanks you very much

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAYXZx8dCU5ydr6B383kMgdMSxsg7i9vuJUyo7HjJ1g-EJMmZw%40mail.gmail.com.

Reply via email to