Skip to content

TextRegion.ln() not working properly when h is provided #1786

@One-Nose

Description

@One-Nose

When using text regions, calling ln() with a custom h value will cause an unwanted second line break after the first line of the next paragraph.

Minimal code

import fpdf

pdf = fpdf.FPDF()
pdf.set_font("Helvetica", size=16)
pdf.add_page()

pdf.write(text="GOOD\nGOOD")
pdf.ln(16)
pdf.write(text="GOOD\nGOOD")

pdf.ln(16)

with pdf.text_columns() as region:
    region.write(text="BAD\nBAD")
    region.ln(16)
    region.write(text="BAD\nBAD")

pdf.output("output.pdf")

Result PDF looks something like this:

GOOD
GOOD

GOOD
GOOD

BAD
BAD

BAD

BAD

As you can see an uncalled for line break was added before the last line.

Environment

  • Operating System: Windows
  • Python version: 3.14
  • fpdf2 version used: 2.8.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions