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

print headers on page break #1152

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions fpdf/fpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3417,6 +3417,7 @@ def _perform_page_break_if_need_be(self, h):
h,
self.page_break_trigger,
)

self._perform_page_break()
return True
return False
Expand Down Expand Up @@ -3481,6 +3482,7 @@ def multi_cell(
output=MethodReturnValue.PAGE_BREAK,
center=False,
padding=0,
page_break_buffer=0,
):
"""
This method allows printing text with line breaks. They can be automatic
Expand Down Expand Up @@ -3587,7 +3589,6 @@ def multi_cell(
new_x = XPos.coerce(new_x)
new_y = YPos.coerce(new_y)
if ln != "DEPRECATED":
# For backwards compatibility, if "ln" is used we overwrite "new_[xy]".
if ln == 0:
new_x = XPos.RIGHT
new_y = YPos.NEXT
Expand Down Expand Up @@ -3697,12 +3698,13 @@ def multi_cell(

for text_line_index, text_line in enumerate(text_lines):
page_break_required = self.will_page_break(h + padding.bottom)
#when the page breaks print the headers on the new page
if page_break_required:
page_break_triggered = True
x = self.x
self.add_page(same=True)
self.x = x
self.y += padding.top
self.y += padding.top + page_break_buffer

if box_required and (text_line_index == 0 or page_break_required):
# estimate how many cells can fit on this page
Expand Down
28 changes: 28 additions & 0 deletions fpdf/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ def _render_table_cell(
wrapmode=self._wrapmode,
padding=padding,
link=cell.link,
page_break_buffer=10,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no "magical numbers" like that in the code.
How did you arrive at exactly this size?
Are you aware that size specifications are relative to the document units? If someone uses inches as document units, this turns into half a page!

**kwargs,
)

Expand All @@ -510,6 +511,33 @@ def _render_table_cell(

do_pagebreak = page_break_text or page_break_image

if do_pagebreak and not height_query_only:
row_info = list(self._process_rowpans_entries())
if self._num_heading_rows:
self._fpdf.y = self._fpdf.t_margin
x1 = self._fpdf.x - col_width
y1 = self._fpdf.y
x2 = (
self._fpdf.x
) # already includes gutter for cells spanning multiple columns
y2 = y1 + cell_height
draw_box_borders(
self._fpdf,
x1,
y1,
x2,
y2,
border=self.get_cell_border(i, j, cell),
fill_color=style.fill_color if style else None,
)

#the text is being overlapped by the header. add some margin at the top of the text when page break
for row_idx in range(self._num_heading_rows):
self._render_table_row(
row_idx,
row_info[row_idx],
cell_x_positions=cell_x_positions,
)
return do_pagebreak, img_height, cell_height

def _get_col_width(self, i, j, colspan=1):
Expand Down