From 844eb7f70e9ac2c7b77876eee48101c195d9306f Mon Sep 17 00:00:00 2001 From: Gael Le Mignot Date: Wed, 17 Nov 2021 10:08:14 +0100 Subject: [PATCH] Using weasyprint for pdf generation --- teleforma/views/core.py | 1 - teleforma/views/pro.py | 11 ++++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/teleforma/views/core.py b/teleforma/views/core.py index 0f37c2d8..b40edb6a 100644 --- a/teleforma/views/core.py +++ b/teleforma/views/core.py @@ -84,7 +84,6 @@ from telemeta.views import * from teleforma.context_processors import * import jqchat.models from xlwt import Workbook -from xhtml2pdf import pisa try: from telecaster.models import * diff --git a/teleforma/views/pro.py b/teleforma/views/pro.py index 182c8896..a283dcbf 100644 --- a/teleforma/views/pro.py +++ b/teleforma/views/pro.py @@ -56,7 +56,7 @@ import os, datetime from cgi import escape from cStringIO import StringIO -from xhtml2pdf import pisa +import weasyprint import time import json @@ -77,10 +77,11 @@ def content_to_pdf(content, dest, encoding='utf-8', **kwargs): Write into *dest* file object the given html *content*. Return True if the operation completed successfully. """ - from xhtml2pdf import pisa + print("Write PDF 2") src = StringIO(content.encode(encoding)) - pdf = pisa.pisaDocument(src, dest, encoding=encoding, **kwargs) - return not pdf.err + src = weasyprint.HTML(string=content.encode(encoding), encoding=encoding) + dest.write_pdf(result) + return True def content_to_response(content, filename=None): """ @@ -694,7 +695,7 @@ class PDFTemplateResponseMixin(TemplateResponseMixin): template_name = 'myapp/myview.html' pdf_filename = 'report.pdf' - The pdf generation is automatically done by *xhtml2pdf* using + The pdf generation is automatically done by *weasyprint* using the *myapp/myview_pdf.html* template. Note that the pdf template takes the same context as the normal template. -- 2.39.5