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

write_html skips one line when the line wraps inside a word (no spaces available for wrapping) #847

Closed
stenci opened this issue Jul 10, 2023 · 1 comment

Comments

@stenci
Copy link

stenci commented Jul 10, 2023

The following code should write two strings on the same position.

Instead the blue string wraps in the correct way and is printed in the correct position, while the red string does wrap in the correct way, but is printed after skipping one empty line.

from fpdf import FPDF

pdf = FPDF()
pdf.add_page()
pdf.set_font(family='Helvetica', size=20)

# print one blue long line without spaces
pdf.set_xy(10, 10)
pdf.set_text_color(255, 0, 0)
pdf.write_html('X' * 50)

# print one red long line with spaces
pdf.set_xy(10, 10)
pdf.set_text_color(0, 0, 255)
pdf.write_html('Y' * 25 + ' ' + 'Y' * 25)

pdf.output('html.pdf')

This is the output:
image

The code above is a simple minimal example, and it's hard to believe that one may need such a long text to correctly wrap. But in my real application I play with margins and use write_html to write formatted text in a table-like format (because tables do not allow font tags or other formatting techniques inside a cell.)

Here is an example of the result of my function, where write_html has ben used to write text in different sizes and colors in a table format. Notice the text highlighted in red, which is shifted down one line:
image

Environment

  • Operating System: Windows
  • Python version: 3.7
  • fpdf2 version used: 2.7.4
@Lucas-C
Copy link
Member

Lucas-C commented Jul 10, 2023

Thank you for the report @stenci

I opened #850 in order to fix this

@gmischler would you kindly review this pull request please?

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