]> git.parisson.com Git - teleforma.git/commitdiff
Switched to weasyprint and fixed billind CSSĂ©
authorGael Le Mignot <gael@pilotsystems.net>
Fri, 4 Jun 2021 08:43:12 +0000 (10:43 +0200)
committerGael Le Mignot <gael@pilotsystems.net>
Fri, 4 Jun 2021 08:43:12 +0000 (10:43 +0200)
requirements.txt
teleforma/static/teleforma/css/teleforma_receipt_pdf.css
teleforma/views/core.py

index 0372fcfc9dc98738682685840610b7d4731f1114..c88073bb8f5967879f82cdccc0756d49fb6364b8 100644 (file)
@@ -20,7 +20,7 @@ numpy==1.20.3
 # html5lib==1.1
 sorl-thumbnail==12.7.0
 unidecode==1.2.0
-xhtml2pdf==0.2.5
+weasyprint==52.5
 xlrd==2.0.1
 xlwt==1.3.0
 psycopg2==2.8.6 
index 52d7d96115e1b54fc2f3f2644ea30816386895aa..f755a922ce211679e7a1bc2981cd3f0c78d857f8 100644 (file)
@@ -29,7 +29,7 @@
 
 
 #content .address p{
-    margin-left: 55%;
+    margin-left: 5%;
     line-height: 20px;
     font-size: 14px;
     font-weight: bold;
@@ -54,7 +54,7 @@
 
 #content table{
     margin-top: 30px;
-    width: 100%;
+    width: 96%;
     line-height: 20px;
     border-spacing : 0;
     border-collapse : collapse;
@@ -62,8 +62,8 @@
 }
 
 #content table tr th{
-    padding: 5px;
-    font-size: 14px;
+    padding: 4px;
+    font-size: 12px;
     border: 1px solid #000;
 }
 
 }
 
 #content table tr th:first-child{
-    width: 60%;
+    width: 56%;
 }
 
 #content table tr td{
-    padding: 15px 5px;
+    padding: 12px 4px;
     border-left: 1px solid #000;
     border-right: 1px solid #000;
     line-height: 24px;
-    font-size: 14px;
+    font-size: 12px;
     font-weight: bold;
 }
 #content table tr td:first-child{
index a4c9807816baf9372b8f93b5d5a353d9fcb74687..526ab4acf89b7ff2f1569f2554cbddda01e6c7c7 100644 (file)
@@ -59,7 +59,7 @@ from django.views.generic.list import ListView
 from jsonrpc import jsonrpc_method
 from jsonrpc.proxy import ServiceProxy
 from teleforma.models.crfpa import Home
-from xhtml2pdf import pisa
+import weasyprint
 
 from ..decorators import access_required
 from ..models.appointment import Appointment, AppointmentPeriod
@@ -195,10 +195,9 @@ 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.
     """
-    src = BytesIO(content.encode(encoding))
-    pdf = pisa.pisaDocument(src, dest, encoding=encoding, **kwargs)
-    return not pdf.err
-
+    src = weasyprint.HTML(string = content, encoding = encoding)
+    src.write_pdf(dest)
+    return True
 
 def content_to_response(content, filename=None):
     """
@@ -216,6 +215,7 @@ def render_to_pdf(request, template, context, filename=None, encoding='utf-8',
     Render a pdf response using given *request*, *template* and *context*.
     """
     content = loader.render_to_string(template, context, request = request)
+    #return HttpResponse(content)
     buffer = BytesIO()
 
     succeed = content_to_pdf(content, buffer, encoding, **kwargs)
@@ -1010,7 +1010,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.