CSS not rendered by Pisa's pdf generation in Django
You could try this 'Pisa-and-Reportlab-pitfalls'
I had to add this
def fetch_resources(uri, rel):
On top of that I still carry all my css within the template. Also make sure you're using xhtml2pdf and not the old ho.pisa.
Is there a way to generate pdf containing non-ascii symbols with pisa from django template?
This does work for me:
pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("UTF-8")), result, encoding='UTF-8')
django - pisa : adding images to PDF output
I got the images working. the code is as follows:
from django.http import HttpResponse
from django.template.loader import render_to_string
from django.template import RequestContext
from django.conf import settings
import ho.pisa as pisa
import cStringIO as StringIO
import cgi
import os
def dm_monthly(request, year, month):
html = render_to_string('reports/dmmonthly.html', { 'pagesize' : 'A4', }, context_instance=RequestContext(request))
result = StringIO.StringIO()
pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("UTF-8")), dest=result, link_callback=fetch_resources )
if not pdf.err:
return HttpResponse(result.getvalue(), mimetype='application/pdf')
return HttpResponse('Gremlins ate your pdf! %s' % cgi.escape(html))
def fetch_resources(uri, rel):
path = os.path.join(settings.MEDIA_ROOT, uri.replace(settings.MEDIA_URL, ""))
return path
This was taken liberally from http://groups.google.com/group/xhtml2pdf/browse_thread/thread/4cf4e5e0f4c99f55
Related Topics
Pandas Extract Number from String
Install Rpy2 on Windows7 64Bit for Python 2.7
Efficient Ways to Duplicate Array/List in Python
Swift Playground Error: Module 'Python' Has No Member Named 'Import'
How to Exchange Keys with Values in a Dictionary
Quick Way to Upsample Numpy Array by Nearest Neighbor Tiling
Which Is the Recommended Way to Plot: Matplotlib or Pylab
Understanding Python's Call-By-Object Style of Passing Function Arguments
Remove Xticks in a Matplotlib Plot
Python How to Parse CSS File as Key Value
Converting Yes and No to 0 and 1 in R
Differencebetween Ruby and Python Versions Of"Self"
Is There a Function That Checks If a Character in a String Is a Letter in the Alphabet? (Swift)