Convert a csv file to PDF using Python

3k views Asked by At

I have a dictionary which I converted to a csv file using pandas dataframe. Below is my csv file:

date,time,type,text,start,end,Year,Movies.type
20/10/15,10:00:00,Horror,"adadadasdsfs
sdsdfsdfasdfsfdf 
   fsdfasdfsfsfsdfs",00:00:00,02:59:13,2015,Horror
20/10/15,11:00:00,Horror,"abc",00:00:00,03:00:00,2015,Horror

I want this file to be converted to PDF using Python. I found that we can use pyfpdf/pdfkit. In what aspects are they different ?

Which module should I use ? How to convert using that module?

1

There are 1 answers

6
Gustav Rasmussen On

I recommend using pypandoc. It can be done like this:

import pypandoc

output = pypandoc.convert_file('somefile.csv', 'pdf', outputfile="somefile.pdf")
assert output == ""