Stip HTML from text in PDFs except for <br>, make <br> not break things

This commit is contained in:
Raphael Michel
2018-02-04 19:45:00 +01:00
parent bab7f9b1f3
commit 6aee1ee41f

View File

@@ -1,9 +1,11 @@
import copy
import logging
import re
import uuid
from collections import OrderedDict
from io import BytesIO
import bleach
from django.contrib.staticfiles import finders
from django.core.files import File
from django.core.files.storage import default_storage
@@ -242,8 +244,14 @@ class PdfTicketOutput(BaseTicketOutput):
textColor=Color(o['color'][0] / 255, o['color'][1] / 255, o['color'][2] / 255),
alignment=align_map[o['align']]
)
p = Paragraph(self._get_text_content(op, order, o) or "", style=style)
text = re.sub(
"<br[^>]*>", "<br/>",
bleach.clean(
self._get_text_content(op, order, o) or "",
tags=["br"], attributes={}, styles=[], strip=True
)
)
p = Paragraph(text, style=style)
p.wrapOn(canvas, float(o['width']) * mm, 1000 * mm)
# p_size = p.wrap(float(o['width']) * mm, 1000 * mm)
ad = getAscentDescent(font, float(o['fontsize']))