django-easy-pdf
django-easy-pdf copied to clipboard
Word wrap not working
Hello, I have been using easy_pdf to render pdfs from an html template. But I have not been able to wrap long words. It works fine with line wrapping. But when the text contains a link, it does not break.
word-wrap: break-word; is not working.
Me too, i can't break line on td table :cry:
Same. Using a table and can't wrap long text.
I've implemented a simple django filter as a workaround to this issue:
from textwrap import wrap
from django import template
register = template.Library()
@register.filter
def text_wrap(text, width=70):
"""
The used PDF libs don't allow CSS word-wrap, so to split long words (e.g. urls)
we wrap the text by lines and join them with spaces to have multiple lines. See:
https://github.com/nigma/django-easy-pdf/issues/65
https://github.com/xhtml2pdf/xhtml2pdf/issues/379
"""
return ' '.join(wrap(text, width))
In the html template I just import and use the custom filter:
{% load pdf_filters %}
{{ my_long_value|text_wrap }}
where to import these line of code,