Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cc3df89

Browse files
author
Soumitra
committed
python csv to pdf file
1 parent 79dfcc9 commit cc3df89

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import csv
2+
from fpdf import FPDF
3+
4+
with open('student.csv', newline='') as f:
5+
reader = csv.reader(f)
6+
7+
pdf = FPDF()
8+
pdf.add_page()
9+
page_width = pdf.w - 2 * pdf.l_margin
10+
11+
pdf.set_font('Times','B',14.0)
12+
pdf.cell(page_width, 0.0, 'Students Data', align='C')
13+
pdf.ln(10)
14+
15+
pdf.set_font('Courier', '', 12)
16+
17+
col_width = page_width/4
18+
19+
pdf.ln(1)
20+
21+
th = pdf.font_size
22+
23+
for row in reader:
24+
#print(row)
25+
pdf.cell(col_width, th, str(row[0]), border=1)
26+
pdf.cell(col_width, th, row[1], border=1)
27+
pdf.cell(col_width, th, row[2], border=1)
28+
pdf.cell(col_width, th, row[3], border=1)
29+
pdf.ln(th)
30+
31+
pdf.ln(10)
32+
33+
pdf.set_font('Times','',10.0)
34+
pdf.cell(page_width, 0.0, '- end of report -', align='C')
35+
36+
pdf.output('student.pdf', 'F')

python-csv-to-pdf/readme.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
You can go through the tutorial https://www.roytuts.com/how-to-convert-csv-file-to-pdf-file-using-pyfpdf-in-python/

python-csv-to-pdf/student.csv

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
student_id,student_dob,student_email,student_address
2+
1,01-01-1980,[email protected],Garifa
3+
2,01-01-1982,[email protected],Garia
4+
3,01-01-1982,[email protected],Salt Lake
5+
4,01-01-1992,[email protected],Alipore
6+
5,01-01-1990,[email protected],Salt Lake

python-csv-to-pdf/student.pdf

1.55 KB
Binary file not shown.

0 commit comments

Comments
 (0)