You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am struggling to handle pagebreaks with multicell tables.
As you can see the rest of the row gets printed on the y position of the next page, not the first one.
I am using user input from a pyqt application. This is my code snippet from the application:
the second part is a minimal reproducible example to highlight the problem.
I don't know if I have a logic error, or fpdf is not viable for this approach. This is something for an invoice generator.
def add_table_row(pdf, product, widths, alignments):
pdf.set_font('Helvetica', '', 9)
x_start = 25
y_before = pdf.get_y()
max_y = y_before
for width, field, align in zip(widths, product, alignments):
# Set x position to 25 for the first column
pdf.set_xy(x_start, y_before)
pdf.multi_cell(width, 5, field, border=1, align=align)
x_start += width # Move x position for the next column
max_y = max(max_y, pdf.get_y())
pdf.set_y(max_y)
# Add table rows
for idx, product in enumerate(product_lines, start=1):
current_y = pdf.get_y()
if current_y + 10 > pdf.h - 25:
pdf.add_page()
current_y = 25 # Set Y position to top margin for new page
pdf.set_xy(25, current_y) # Reset X position for the new row
formatted_menge = f"{locale.format_string('%.2f', product['menge'], grouping=True)} {product['einheit']}"
formatted_preis_netto = f"{locale.format_string('%.2f', product['preis_netto'], grouping=True)} EUR"
formatted_betrag_netto = f"{product['betrag_netto']} EUR"
product_data = [str(idx) + '.', product['produktname'], formatted_menge,
formatted_preis_netto, product['ust'] + ' %', formatted_betrag_netto]
add_table_row(pdf, product_data, widths, alignments)
I am struggling to handle pagebreaks with multicell tables.
![example pdf](https://private-user-images.githubusercontent.com/171875651/337030258-955047bb-2d4c-46a2-8af4-1dd17051cd82.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk5NzYwMTQsIm5iZiI6MTcxOTk3NTcxNCwicGF0aCI6Ii8xNzE4NzU2NTEvMzM3MDMwMjU4LTk1NTA0N2JiLTJkNGMtNDZhMi04YWY0LTFkZDE3MDUxY2Q4Mi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzAzJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcwM1QwMzAxNTRaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT03NDk5OTUyZmI2NjkzMTY1NmFkZDQ4NDQxZWNiNjJjODk1Zjk2ODZjODg2MTQ5ZTBkN2I5MDA0ODYxMjczOWI0JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.XLg_Lcyle8Q42TrylkcGwBreaORs8GCzicrLbAZ0m4E)
As you can see the rest of the row gets printed on the y position of the next page, not the first one.
I am using user input from a pyqt application. This is my code snippet from the application:
the second part is a minimal reproducible example to highlight the problem.
I don't know if I have a logic error, or fpdf is not viable for this approach. This is something for an invoice generator.
thanks in advance for any tips/help
The text was updated successfully, but these errors were encountered: