ไม่สามารถเล่นวิดีโอนี้
ขออภัยในความไม่สะดวก
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
Wow, thanks again for the help, i dont know what i would do without you!
Thanks for your support 😀
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.
Thanks! I'm glad it can help you out on your project. Good luck :)
Thank you for a great series on PDF creation!
I need a Multiple line content in cell
Can you make thise ?
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)
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.
Thank you for a great series on PDF creation!
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?
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'
awesome..thanks GREAT JOB
Thank you!
Outstanding!
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'
Good to know! Thanks.
thanks for this great python library,i wonder if there is a way to insert qrcode or pic in the table?
how to repeat table header on all pages?
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
same error , im still not able to resolve
How to add an Image Inside a Cell in FPDF2 ?
It would be really helpful if you could answer.
Thanks for the video.
nice. i will watch it soon
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.
i tried converting a pandas dataframe to a python dictionary, and then use the dict as data
Amazing work.
Thank you.
By the way, is there a way to keep up with the headers when the table continues on another page? Tks
@@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.
thank you very much is there any option to append a created table to an existing pdf file, and erase the borders ?
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
Great video
Thanks!
How can i add some text and with that only an image as well in the same cell?
Have you found a way to merge vertical cells?
how did you have a solution to display two table side by side with fpdf
Is there a method to set the line color? e.g., set_draw_color
Great video! . Is it possible to use your table class with csv files or pandas dataframes?
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?
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
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
how can we show the data from the treeview?
please make tutorial how to make crm database in sqlite3 to pdf. Thanks for your response
What if the data is from a dataframe?
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?
i have resolved this. there is a bug with the use of dicts. i simply reformed my data in lols and it worked.
Hi Brandon, I tried using the class version and I keep getting error message regarding PDF has no attribute 'epw'.
I get the same error. Any luck solving this?
@@scottnorman2296 I installed fpdf2 without other dependencies. Worked for me. (pip install --no-dependencies fpdf2)
@@rambaldi10 thank you!!
Thank you
how to create borders around the table and wrap the long text inside them
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.
@@ChartExplorers Thank you so much for your reply. Can i add another table inside a table?
@@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!
how to write in arabic ?
please i need a help