python-csv-to-pdf.py 748 B

123456789101112131415161718192021222324252627282930313233343536
  1. import csv
  2. from fpdf import FPDF
  3. with open('student.csv', newline='') as f:
  4. reader = csv.reader(f)
  5. pdf = FPDF()
  6. pdf.add_page()
  7. page_width = pdf.w - 2 * pdf.l_margin
  8. pdf.set_font('Times','B',14.0)
  9. pdf.cell(page_width, 0.0, 'Students Data', align='C')
  10. pdf.ln(10)
  11. pdf.set_font('Courier', '', 12)
  12. col_width = page_width/4
  13. pdf.ln(1)
  14. th = pdf.font_size
  15. for row in reader:
  16. #print(row)
  17. pdf.cell(col_width, th, str(row[0]), border=1)
  18. pdf.cell(col_width, th, row[1], border=1)
  19. pdf.cell(col_width, th, row[2], border=1)
  20. pdf.cell(col_width, th, row[3], border=1)
  21. pdf.ln(th)
  22. pdf.ln(10)
  23. pdf.set_font('Times','',10.0)
  24. pdf.cell(page_width, 0.0, '- end of report -', align='C')
  25. pdf.output('student.pdf', 'F')