From: Gael Le Mignot Date: Fri, 4 Jun 2021 08:43:12 +0000 (+0200) Subject: Switched to weasyprint and fixed billind CSSé X-Git-Tag: 2.1~66^2^2~42 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=34c4e9ab42b10c2a8f189bc705679a2d1f6224b7;p=teleforma.git Switched to weasyprint and fixed billind CSSé --- diff --git a/requirements.txt b/requirements.txt index 0372fcfc..c88073bb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/teleforma/static/teleforma/css/teleforma_receipt_pdf.css b/teleforma/static/teleforma/css/teleforma_receipt_pdf.css index 52d7d961..f755a922 100644 --- a/teleforma/static/teleforma/css/teleforma_receipt_pdf.css +++ b/teleforma/static/teleforma/css/teleforma_receipt_pdf.css @@ -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; } @@ -72,15 +72,15 @@ } #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{ diff --git a/teleforma/views/core.py b/teleforma/views/core.py index a4c98078..526ab4ac 100644 --- a/teleforma/views/core.py +++ b/teleforma/views/core.py @@ -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.