Webservice return pdf

68 views
Skip to first unread message

Madhu

unread,
May 28, 2012, 7:51:59 AM5/28/12
to django...@googlegroups.com
Hi! all
I create client & through client i call the web service.
which returns pdf file, i want to stored that file directly.
I use this
response['Content-Disposition'] = 'attachment; filename= 'demo.pdf'
but it will ask the user to store the file, but i want to store it automatically on server.
can anybody please suggest me, how it should be done?

Thanks

francescortiz

unread,
May 29, 2012, 1:17:48 PM5/29/12
to django...@googlegroups.com
a search for

python write file

migh help

Benedict Verheyen

unread,
May 31, 2012, 10:16:24 AM5/31/12
to django...@googlegroups.com
If you use response in the way you do, it will indeed ask to store the file.
As you seem to be able to present the pdf file, I don't see why you can't write the file
to a media directory?
You can then serve up these files directly or via a model.

It's not actually clear what you want to accomplish exactely.

Cheers,
Benedict


Sells, Fred

unread,
May 31, 2012, 6:07:47 PM5/31/12
to django...@googlegroups.com
Here's how I merge .fdf with pdf

def getPDFContent(assessment):
completedfdf = getCompletedForm(assessment)
pdffilename = getFilename(assessment, 'forms') +".pdf"
pdftk = ["/usr/bin/pdftk" ,'pdftk'][os.name=='nt']
cmd = '%s %s fill_form - output - flatten' % (pdftk,
pdffilename)
proc = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE,
shell=True, bufsize=100000000)
cmdout,cmderr = proc.communicate(completedfdf)
if cmderr != '':
raise cmderr
return cmdout

and here's how I do my response (from views.py)
def getpdf(request, *args, **kwargs):
qs = extract_querystring_from_request(request)
parameters = Parameters(**qs)
assessment = models.Assessment.objects.get(pk=parameters.id)
pdfbuffer = pdfgenerator.getPDF(assessment)
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'inline; filename=filename.pdf'
response.write(pdfbuffer)
return response

I'm no expert, but this works consistently.

Reply all
Reply to author
Forward
0 new messages