Comments (3)
What you need here is an unbreakable-section.
Interestingly, your example revealed a minor bug related to the page breaks logic,
on some very specific conditions, when the overflow check compares two values that are equal.
You can find the details, and a usage example of unbreakable()
, in this PR:
https://github.com/PyFPDF/fpdf2/pull/155/files
from fpdf2.
Interesting, thank you for the issue report!
I opened #121 to solve this case
I plan on merging it & generating a new release this week-end.
from fpdf2.
First of, Awesome light weight library!
So Im using the latest release and I also come across the same issue. Here is an example to replicate
import pandas as pd
from fpdf import FPDF
index=range(0,19)
columns=['A']
test = pd.DataFrame(index=index, columns=columns)
test['A']="test_lin_o_00000_001"
test['B'] = '3'
test['C'] = '4'
test['D'] = "test_lin_o_00000"
test['E'] = '7'
test['F'] = "test_lin_o_00000"
test['G'] = "test_lin"
test['H'] = "test_lin"
test_list = list(zip(test ["A"] ,test["B"],test ["C"],
test ["D"],test["E"],test ["F"],test["G"],
test["H"]))
test_titles = (("A","B","C","D","E","F","G","H"))
columns_test = [test_titles ]
class CustomPDF(FPDF):
def header(self):
# Set up a logo
self.image('https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png', 160, 3, 25)
self.set_font('Arial', 'B', 30)
# Line break
self.ln(20)
def footer(self):
self.set_y(-10)
self.set_font('Arial', 'I', 8)
# Add a page number
page = 'Page ' + str(self.page_no()) + '/{nb}'
self.cell(0, 10, page, 0, 0, 'C')
def create_pdf(pdf_path):
pdf = CustomPDF()
pdf.alias_nb_pages()
pdf.add_page()
pdf.set_margins(20, 20)
pdf.set_text_color(50, 139, 168)
pdf.set_font('Arial', '', 13)
pdf.cell(0, 6, f'{"test"}')
pdf.ln(5)
pdf.set_text_color(0, 0,0)
pdf.set_font('Times','B',size=7)
line_height = pdf.font_size * 3
col_width = pdf.epw / 8
for row in columns_test :
for datum in row:
pdf.multi_cell(col_width, line_height, datum, border=1, ln=3, max_line_height=pdf.font_size,align='C')
pdf.ln(line_height)
pdf.set_font('Times',size=7)
line_height = pdf.font_size * 10
col_width = pdf.epw / 8
for row in test_list:
for datum in row:
pdf.multi_cell(col_width, line_height, datum, border=1, ln=3, max_line_height=pdf.font_size,align='C')
pdf.ln(line_height)
pdf.output(pdf_path)
if __name__ == '__main__':
create_pdf('test.pdf')
What I noticed is that this have to do with the test['A'] containing large characters . If you drop some characters eg. test["A"] = test['A'].str.replace("test_", "")
and redo the same thing it will works but I do need those original columns. Is here is way around this?
from fpdf2.
Related Issues (20)
- Word wrapping for Thai text (zero-width space) may not work as intended // wrapmode==WORD should also use zero-width space? HOT 2
- Add Cell Level Controll for Table Borders HOT 1
- Wrong signature for `pdf.table` HOT 4
- OSS-Fuzz Integration HOT 8
- multipage table using fpdf HOT 2
- Get rid of FPDF class/instance attributes getting passed to HTML2PDF. HOT 5
- Proposal for Generic Robust Substitution Mechanism HOT 1
- `local_context()` blocks appear to "leak" into one another HOT 6
- HTML: indent of lists on new line not flush HOT 5
- Line spacing for a long line that is displayed in several lines. HOT 5
- Text columns issue with top margin HOT 1
- Markdown not escaping MD special characters HOT 3
- Solution needed: Typographical Margins, Line Height, Leading HOT 1
- write_html() ignores font changes HOT 4
- call .write_html in footer cause RecursionError HOT 1
- pdf.font_style = "B" and pdf.emphasis = "BOLD" should behave the same way as pdf.set_font(style="B") HOT 1
- Lowercase hex (e.g. #fff) do not convert properly HOT 5
- Stampapdf HOT 3
- FPDF.unbreakable() drops table instead of adding page break beforehand HOT 1
- Determine string width before detecting the language of the string and applying this setting to the font shape engine leads to wrong get_string_width() HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fpdf2.