convert txt to pdf python

Solutions on MaxInterview for convert txt to pdf python by the best coders in the world

showing results for - "convert txt to pdf python"
Anas
25 Apr 2018
1pip install fpdf
2from fpdf import FPDF
3# save FPDF() class into  
4# a variable pdf 
5pdf = FPDF()    
6   
7# Add a page 
8pdf.add_page() 
9   
10# set style and size of font  
11# that you want in the pdf 
12pdf.set_font("Arial", size = 15) 
13  
14# open the text file in read mode 
15f = open("myfile.txt", "r") 
16  
17# insert the texts in pdf 
18for x in f: 
19    pdf.cell(200, 10, txt = x, ln = 1, align = 'C') 
20   
21# save the pdf with name .pdf 
22pdf.output("mygfg.pdf")