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

Bug: <center> does not support internal HTML tags #640

Closed
Lucas-C opened this issue Dec 22, 2022 · 8 comments
Closed

Bug: <center> does not support internal HTML tags #640

Lucas-C opened this issue Dec 22, 2022 · 8 comments

Comments

@Lucas-C
Copy link
Member

Lucas-C commented Dec 22, 2022

Minimal code reproducing the issue:

from fpdf import FPDF

pdf = FPDF()
pdf.add_page()
pdf.write_html("""<center>
    <p>Some dummy text</em>, and <b>some in bold</b>,
    and finally <a href="https://github.com/PyFPDF/fpdf2">an hyperlink</a>.</p>
</center>""")
pdf.output("issue_640.pdf")

Produces: issue_640.pdf

This issue is related to #91 & #151

@ssavi-ict
Copy link

Hi @Lucas-C , I am trying to understand this issue. Could not get in properly though.
I tried to run a html code with following -

<!DOCTYPE html>
<html>
<body>
<center>
    <p>Some dummy text</em>, and <b>some in bold</b>,
    and finally <a href="https://github.com/PyFPDF/fpdf2">an hyperlink</a>.</p>
</center>
</body>
</html>

It gives following output -

"Some dummy text, and some in bold, and finally an hyperlink".

And I am getting the Bug here. Can you explain a bit?

@Lucas-C
Copy link
Member Author

Lucas-C commented Apr 13, 2023

Hey @ssavi-ict!

Thank you for looking at other opportunities to contribute to fpdf2! 👍
It's nice that you took the time to look into this and even tested how a web browser renders this HTML code 😊

You must have seen something like this when rendering this HTML snippet in a browser:
fpdf-center-bug

If you compare with the PDF included in the issue description,
obtained by running the provided Python script that uses fpdf2,
you'll see that in the PDF generated the text is split over several lines.

What we would like is to have the same viual result in both case,
and that means fixing fpdf2 in order to get a single line of text in that case, when using <center></center>

This is not a very easy task, as it will probably mean making changes to how HTML2FPDF handle <center> tags in html.py,
maybe using FPDF.mult_cell() in those cases.

@gmischler
Copy link
Collaborator

This is one of the many things that #339 is meant to solve.

I hope I'll get https://github.com/gmischler/fpdf2/tree/TextRegion to a state soon that makes it suitable for a PR (currently in a heavy refactoring phase). Once the basic functionality is in place, write_html() can use that to solve "all" formatting problems including this one.

@Lucas-C
Copy link
Member Author

Lucas-C commented Apr 14, 2023

This is one of the many things that #339 is meant to solve.

I hope I'll get gmischler/fpdf2@TextRegion to a state soon that makes it suitable for a PR (currently in a heavy refactoring phase). Once the basic functionality is in place, write_html() can use that to solve "all" formatting problems including this one.

That would be awesome 😊

Do you think that other fpdf2 contributors could help you with this task?
Could it be broken down into small PRs?

@gmischler
Copy link
Collaborator

Do you think that other fpdf2 contributors could help you with this task?
Could it be broken down into small PRs?

Implementing the core concepts is not easily divisible, because I need to figure out the best interaction between various parts of the system. The first attempt has been sitting idle for a while, sorry for that. I've started a refactor as a result of our recent discussion about tables and will try to get it to a presentable state "real soon now"...

Once the base system is in place, specialized subclasses for specific tasks should be reasonably easy to add by others (eg. table cells, TOCs, arbitrarily shaped outlines, etc.).

@ssavi-ict
Copy link

@gmischler , Thanks for the update. As you are working on this now, I think I should look for other issues.
What do you suggest?

@Lucas-C any suggestion?

@Lucas-C
Copy link
Member Author

Lucas-C commented Apr 14, 2023

As you are working on this now, I think I should look for other issues. What do you suggest?

@Lucas-C any suggestion?

Well you could have a look at our issues labeled good first issue, even if you are starting to become a regular contributor now @ssavi-ict ^^: https://github.com/PyFPDF/fpdf2/labels/good%20first%20issue

Specifically, you could have a look at those ones:

Also, if you have other ideas for combining fpdf2 with other existing Python libs,
you can test it out and then write some documentation pages describing how to do so!

@gmischler
Copy link
Collaborator

I've just checked in #897, which should solve this problem.

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

3 participants