diff --git a/main/pdf.py b/main/pdf.py index 418c5df..88d6755 100644 --- a/main/pdf.py +++ b/main/pdf.py @@ -4,21 +4,29 @@ # - http://stackoverflow.com/questions/1377446/html-to-pdf-for-a-django-site # - http://stackoverflow.com/questions/2179958/django-pisa-adding-images-to-pdf-output ? # - http://web.archive.org/web/20090413054650/http://www.xhtml2pdf.com/doc/pisa-en.html +import os +from cgi import escape +from django.template.loader import render_to_string +from django.template import RequestContext +from django.conf import settings +from django.http import HttpResponse import cStringIO as StringIO import ho.pisa as pisa -from django.template.loader import get_template -from django.template import Context -from django.http import HttpResponse -from cgi import escape -def render_to_pdf(template_src, context_dict): - template = get_template(template_src) - context = Context(context_dict) - html = template.render(context) +def render_to_pdf(template_src, context_dict, context_instance): + html = render_to_string(template_src, context_dict, context_instance=context_instance) result = StringIO.StringIO() - pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("UTF-8")), result) + 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('We had some errors
%s' % escape(html)) + +def fetch_resources(uri, rel): + # Replace the url with the physical path. + path = os.path.join(settings.STATIC_ROOT, uri.replace(settings.STATIC_URL, "")) + return path diff --git a/main/templates/pdf/new_temp_user.html b/main/templates/pdf/new_temp_user.html index cee5127..178efc5 100644 --- a/main/templates/pdf/new_temp_user.html +++ b/main/templates/pdf/new_temp_user.html @@ -20,6 +20,13 @@ .monospace { font-family: monospace; } + .sub_header { + font-size: 0.6em; + margin-bottom:1cm; + } + h1, h2 { + margin-bottom:0px; + } #logo { margin-top: 1cm; } @@ -29,17 +36,22 @@ {% for userpass in log.userpass_set.all %}
+ Tjenesten er levert av EDB-gruppa i Kommunikasjonsvavdelingen - kak-edb@studentersamfundet.no
+ 
