Create PDF Tables with Python FPDF2

preview_player
Показать описание
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
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

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
Рекомендации по теме
Комментарии
Автор

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'

RomansRule
Автор

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\reviewcode\data_pdf_test.py", line 64, in <module>
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\reviewcode\create_table_fpdf2.py", line 107, in create_table
table_width = col_width * len(table_data[0])
KeyError: 0

kalpdalal
Автор

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?

lukoritomelvinwepukhulu
Автор

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.

ramongiovane
Автор

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

Younes_SBIA
Автор

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'

MichaelSmith-twyx
Автор

how to repeat table header on all pages?

adarsh
Автор

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.

simplyviki
Автор

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)

satviklife
Автор

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

hamzashabbir
Автор

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 \n isnt working for it

suleman
Автор

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

elmahdibouasri
Автор

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

aimeanzian
Автор

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

SeanMaman-jh
Автор

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

gahowtam
Автор

Have you found a way to merge vertical cells?

JulioDiaz
Автор

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

tumpalmichaels
Автор

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

efembilgic
Автор

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.

tadashitani
Автор

how can we show the data from the treeview?

videosyarego