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

text running out of the <td><> #405

Closed
deepakmeena635 opened this issue Apr 27, 2022 · 3 comments
Closed

text running out of the <td><> #405

deepakmeena635 opened this issue Apr 27, 2022 · 3 comments

Comments

@deepakmeena635
Copy link

deepakmeena635 commented Apr 27, 2022

Describe the bug

  1. the line in second td goes beyond the page
  2. image
  3. on using the part enclosed resets to the start of the td

image

  1. on using bgcolor the text in the entire page from the start of the first occurence of tr with bg color becomes of the same color

you can ignore the last one, i'll raise that as another later issue if needed
Error details
No Exceptions are raised

Minimal code
Please include some minimal Python code reproducing your issue:

from fpdf import FPDF

    from fpdf import FPDF, HTMLMixin

    class myPDF(FPDF, HTMLMixin):
        pass
    o = myPDF()
    o.add_page()

    reds, rede = "<<REDS>>", "<<REDE>>" ##TODO: MAKE CONDITIONAL TO ARGUMENTS 
    greens, greene = "<<GREENS>>", "<<GREENE>>"
    def  toHtml(s1,s2):
        res =  f"""<tr>
                        <td width="50%">{s1}</td>
                        <td width="50%">{s2}</td>
                    </tr>"""
        if reds in s1 or greens in s2:
            res =  f"""<tr >
                            <td   width="50%">{s1}</td>
                            <td    width="50%">{s2}</td>
                        </tr>""".replace(reds, 
                                        "<font color=\"red\">"
                                ).replace(rede,
                                        "</font>"
                                ).replace(greens, 
                                        "<font color=\"green\">"
                                ).replace(greene,
                                        "</font>"
                                )
        return res

    pre_file = f"""this is the {reds}first {rede} line
    this is the second line
    this is a really long third {reds} line that i dont know for {rede} some reason goes beyond the page width"""
    post_file = f"""this is the {greens}first {greene} line
    this is the second line
    this is a really long third {greens} line that i dont know for {greene} some reason goes beyond the page width"""
    
    pdfFile = "".join([toHtml(l1,l2) for l1,l2 in zip(pre_file.split('\n'), post_file.split('\n'))])
    pdfFile = f"<table>{pdfFile}</table>"

    o.set_font('helvetica')
    o.set_font_size(14)
    o.write_html(pdfFile)
    o.output("demo2.pdf",)

Environment

  • OS (Windows, Mac OSX, Linux flavour...): Mac
  • Python version: 3.9
  • fpdf2 version used : master branch
@Lucas-C
Copy link
Member

Lucas-C commented Apr 28, 2022

Hi @deepakmeena635
Thank you for taking the time to report this.

Are you aware of the current limitations of the HTML renderer?
https://pyfpdf.github.io/fpdf2/HTML.html#supported-html-features

Typically, as mentioned in the docs, multi-lines cells (= automatic line wrapping) are not supported: #91

Do you really need to work with HTML?
Otherwise I would recommend to use the multi_cell() method that will provide automatic line wrapping.
You can also find recipes on building tables in the documentation:
https://pyfpdf.github.io/fpdf2/Tables.html

Also, I don't understand this sentence:

on using the part enclosed resets to the start of the td

@Lucas-C
Copy link
Member

Lucas-C commented May 6, 2022

Hi @deepakmeena635

Are you still interested on solving this issue, or should we close it?

@deepakmeena635
Copy link
Author

Sure, please close this

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

No branches or pull requests

2 participants