ไม่สามารถเล่นวิดีโอนี้
ขออภัยในความไม่สะดวก

Create PDF Tables with Python FPDF2

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 ส.ค. 2024
  • In this video we go over 4 methods of creating tables. The first two options are built in, but are either unprofessional looking or using HTML which can be cumbersome for larger tables. To overcome these issues, I extended the FPDF class to include a create_table class to easily and professionally make tables when creating a pdf with Python.
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    $15 off Annual Dataquest subscription
    app.dataquest.io/referral-signup/qybqz3r8/
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    Github: github.com/bva...
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    Consider subscribing for weekly tips, tricks, and tutorials. / @chartexplorers
    Join my Discord Server / discord
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    Documentation: pyfpdf.github....
    0:00 Intro
    0:15 Method one (multi-cell)
    0:22 Second Method (HTML)
    0:36 Better Methods Setup
    2:05 create_table class
    5:36 create_table function

ความคิดเห็น • 55

  • @rhysbennett1667
    @rhysbennett1667 3 ปีที่แล้ว +1

    Wow, thanks again for the help, i dont know what i would do without you!

  • @tadashitani
    @tadashitani 3 ปีที่แล้ว +1

    Hi Bradon, very good video, keep up the excellent work. This video is very timely as I need to do exactly this formatting for a project.

    • @ChartExplorers
      @ChartExplorers  3 ปีที่แล้ว

      Thanks! I'm glad it can help you out on your project. Good luck :)

  • @Younes_SBIA
    @Younes_SBIA ปีที่แล้ว +1

    Thank you for a great series on PDF creation!
    I need a Multiple line content in cell
    Can you make thise ?

  • @satviklife7437
    @satviklife7437 4 หลายเดือนก่อน

    Thanks for wonderful tutorial, how could we convert a large csv having 4-5 uneven colomns lenghts, header of CSV should be on top of every PDF page, and PDF grid should be accourding to large line with breaks (to cater in single cell)

  • @ramongiovane
    @ramongiovane 2 ปีที่แล้ว +3

    Thanks for sharing. Your tables look pretty nice.
    I was wondering if you could add the support of multiline cells or make a video showing it. I did not find a good example with FPDF2 yet.

  • @scottnorman2296
    @scottnorman2296 2 ปีที่แล้ว

    Thank you for a great series on PDF creation!

  • @lukoritomelvinwepukhulu1574
    @lukoritomelvinwepukhulu1574 2 ปีที่แล้ว +2

    what if your data is in dictionary form with unequal number of rows and columns e.g 14 x 7 how do you set the width to fit all the data?

  • @RomansRule1234
    @RomansRule1234 ปีที่แล้ว +1

    I get the following error when using even mode:
    line 49, in get_col_widths
    col_width = self.epw / len(data[0]) - 1 # distribute content evenly # epw = effective page width (width of page not including margins)
    AttributeError: 'PDF' object has no attribute 'epw'

  • @mrmuranga
    @mrmuranga 3 ปีที่แล้ว +2

    awesome..thanks GREAT JOB

  • @DarkAcademyUniversity
    @DarkAcademyUniversity 4 หลายเดือนก่อน

    Outstanding!

  • @MichaelSmith-tw6yx
    @MichaelSmith-tw6yx 2 ปีที่แล้ว +2

    If you want to use in cell_width="even" mode, your data structure being passed in needs to be all strings. If your data contains any INTs, you'll get this error message: AttributeError: 'int' object has no attribute 'encode'

  • @gahowtam1377
    @gahowtam1377 8 หลายเดือนก่อน

    thanks for this great python library,i wonder if there is a way to insert qrcode or pic in the table?

  • @adarsh5870
    @adarsh5870 2 ปีที่แล้ว +1

    how to repeat table header on all pages?

  • @kalpdalal6534
    @kalpdalal6534 2 ปีที่แล้ว +1

    My data dictionary is something like this: data_as_dict = {'Study Name': {35: 'Day 8',
    36: 'Day 9',
    37: 'Day 10',
    38: 'Day 11',
    39: 'Day 12',
    40: 'Day 13',
    41: 'Day 14'},
    'Was the NIAID 8-point ordinal scale administered?': {35: 'Yes',
    36: 'Yes',
    37: 'Yes',
    38: 'Yes',
    39: 'Yes',
    40: '',
    41: ''}}
    and I am getting this sort of error: Traceback (most recent call last):
    File "C:\Users\Kalp_Dalal\PycharmProjects
    eviewcode\data_pdf_test.py", line 64, in
    pdf.create_table(table_data = data_as_dict,title='Is my text red',align_header='R', align_data='R', cell_width='uneven', x_start='C', emphasize_data=[], emphasize_style=None,emphasize_color=(0,0,0))
    File "C:\Users\Kalp_Dalal\PycharmProjects
    eviewcode\create_table_fpdf2.py", line 107, in create_table
    table_width = col_width * len(table_data[0])
    KeyError: 0

  • @hamzashabbir3589
    @hamzashabbir3589 ปีที่แล้ว

    How to add an Image Inside a Cell in FPDF2 ?
    It would be really helpful if you could answer.
    Thanks for the video.

  • @mahdisadeghi1838
    @mahdisadeghi1838 ปีที่แล้ว

    nice. i will watch it soon

  • @simplyviki
    @simplyviki 2 ปีที่แล้ว +1

    Thanks, Question: I need to get table values from database and then create a report in pdf, but how to add column headers as those don't come in the query result by default.

    • @gonzalomaidana5429
      @gonzalomaidana5429 2 ปีที่แล้ว +2

      i tried converting a pandas dataframe to a python dictionary, and then use the dict as data

  • @MultiMarcia26
    @MultiMarcia26 3 ปีที่แล้ว +1

    Amazing work.
    Thank you.

    • @MultiMarcia26
      @MultiMarcia26 3 ปีที่แล้ว

      By the way, is there a way to keep up with the headers when the table continues on another page? Tks

    • @ChartExplorers
      @ChartExplorers  3 ปีที่แล้ว

      @@MultiMarcia26 I saw that you asked another question, but I don't see it anymore. Did you figure out your answer? Currently there is not a way to move the headers on to the next page if it is added. I believe some of the table also get's cut off in the margins between pages as well. I need to work on fixing these issues.

  • @user-nj4wk5yi1c
    @user-nj4wk5yi1c ปีที่แล้ว

    thank you very much is there any option to append a created table to an existing pdf file, and erase the borders ?

  • @suleman6432
    @suleman6432 2 ปีที่แล้ว

    Hello Sir I have created the table but their is a problem.I want to show a long string.i want it to be on a new line.But
    isnt working for it

  • @eesakamaldien1917
    @eesakamaldien1917 2 ปีที่แล้ว +1

    Great video

  • @pranshu702
    @pranshu702 ปีที่แล้ว

    How can i add some text and with that only an image as well in the same cell?

  • @JulioDiaz614
    @JulioDiaz614 11 หลายเดือนก่อน

    Have you found a way to merge vertical cells?

  • @aimeanzian
    @aimeanzian ปีที่แล้ว

    how did you have a solution to display two table side by side with fpdf

  • @efembilgic8683
    @efembilgic8683 9 หลายเดือนก่อน

    Is there a method to set the line color? e.g., set_draw_color

  • @ReneFredes
    @ReneFredes ปีที่แล้ว

    Great video! . Is it possible to use your table class with csv files or pandas dataframes?

    • @ReneFredes
      @ReneFredes ปีที่แล้ว

      Solved it. Just followed your comments. I transformed my pandas dataframe into a list of lists by
      listoflists = [df.columns.tolist()] + df.values.tolist()
      Although, another question for anyone reading. How can I draw lines between each table row printed on the pdf?

  • @DeepApnea
    @DeepApnea 2 ปีที่แล้ว

    Hello Brandon, could you please tell me how determinate the position of a table in the PDF?. I saw you have three tables well distributed . Thanks

  • @elmahdibouasri3684
    @elmahdibouasri3684 2 ปีที่แล้ว

    Hello Sir! Actually I work on a project that I should read data from mysql (i'm using pymysql library for that) and I should save the data readed on a pdf file .Can you do a video explain how to do something like that. Thanks

  • @videosyarego
    @videosyarego ปีที่แล้ว

    how can we show the data from the treeview?

  • @tumpalmichaels4085
    @tumpalmichaels4085 3 ปีที่แล้ว

    please make tutorial how to make crm database in sqlite3 to pdf. Thanks for your response

  • @coltonfarrington735
    @coltonfarrington735 2 ปีที่แล้ว

    What if the data is from a dataframe?

  • @BuzzNation69
    @BuzzNation69 ปีที่แล้ว

    this is a great video, but i am having a issue. when i attempt to create a table with 439 rows and 2 columns, FPDF is throwing a mulicell exception: Exception has occurred: FPDFException
    Not enough horizontal space to render a single character ....i dont see where i can modify some horizontal value.....can anyone assist?

    • @BuzzNation69
      @BuzzNation69 ปีที่แล้ว

      i have resolved this. there is a bug with the use of dicts. i simply reformed my data in lols and it worked.

  • @rambaldi10
    @rambaldi10 2 ปีที่แล้ว

    Hi Brandon, I tried using the class version and I keep getting error message regarding PDF has no attribute 'epw'.

    • @scottnorman2296
      @scottnorman2296 2 ปีที่แล้ว

      I get the same error. Any luck solving this?

    • @rambaldi10
      @rambaldi10 2 ปีที่แล้ว +1

      @@scottnorman2296 I installed fpdf2 without other dependencies. Worked for me. (pip install --no-dependencies fpdf2)

    • @MichaelSmith-tw6yx
      @MichaelSmith-tw6yx 2 ปีที่แล้ว

      @@rambaldi10 thank you!!

  • @juliandycaico2110
    @juliandycaico2110 2 ปีที่แล้ว

    Thank you

  • @joblessdev042
    @joblessdev042 3 ปีที่แล้ว

    how to create borders around the table and wrap the long text inside them

    • @ChartExplorers
      @ChartExplorers  3 ปีที่แล้ว

      If you are looking for borders around the table you may want to consider the multicell method. pyfpdf.github.io/fpdf2/Tables.html The text will automatically wrap if it is longer than the width of the cell.

    • @joblessdev042
      @joblessdev042 3 ปีที่แล้ว +1

      @@ChartExplorers Thank you so much for your reply. Can i add another table inside a table?

    • @ChartExplorers
      @ChartExplorers  3 ปีที่แล้ว

      @@joblessdev042 Not that I have been able to figure out. I'll keep thinking about this and let you know if I can come up with anything. Please let me know if you come up with any solution!

  • @salimbentounsi2471
    @salimbentounsi2471 2 ปีที่แล้ว

    how to write in arabic ?
    please i need a help