Giter Club home page Giter Club logo

Comments (3)

Lucas-C avatar Lucas-C commented on August 16, 2024 1

Hi @WalidGharianiEAGLE!

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.

Lucas-C avatar Lucas-C commented on August 16, 2024

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.

WalidGharianiEAGLE avatar WalidGharianiEAGLE commented on August 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.