Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word wrap not working #65

Open
immuntasir opened this issue Nov 24, 2018 · 4 comments
Open

Word wrap not working #65

immuntasir opened this issue Nov 24, 2018 · 4 comments

Comments

@immuntasir
Copy link

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.

@rudmanmrrod
Copy link

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

@djpeacher
Copy link

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

@caumons
Copy link

caumons commented Jun 23, 2021

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

@yashwantrao1
Copy link

where to import these line of code,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants