]> git.parisson.com Git - teleforma.git/commitdiff
Using weasyprint for pdf generation
authorGael Le Mignot <gael@pilotsystems.net>
Wed, 17 Nov 2021 09:08:14 +0000 (10:08 +0100)
committerGael Le Mignot <gael@pilotsystems.net>
Wed, 17 Nov 2021 09:08:14 +0000 (10:08 +0100)
teleforma/views/core.py
teleforma/views/pro.py

index 0f37c2d89dcaa4c93dbe805b12e17486b926fcfa..b40edb6ada0fe47de2ad6c300469bca73c9a7ac4 100644 (file)
@@ -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 *
index 182c88964ef7aa7341b81773f575af3e39c32a0b..a283dcbf77448b205fc97217326106a76d8c45a4 100644 (file)
@@ -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.