django-easy-pdf icon indicating copy to clipboard operation
django-easy-pdf copied to clipboard

Word wrap not working

Open immuntasir opened this issue 6 years ago • 4 comments

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.

immuntasir avatar Nov 24 '18 17:11 immuntasir

Me too, i can't break line on td table :cry:

rudmanmrrod avatar Jan 30 '19 14:01 rudmanmrrod

Same. Using a table and can't wrap long text.

djpeacher avatar Mar 05 '19 20:03 djpeacher

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 }}

caumons avatar Jun 23 '21 13:06 caumons

where to import these line of code,

Maahishu avatar May 31 '23 06:05 Maahishu