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.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment