Hi ππ
In this post, I will share with you How To Convert Text to PDF Using Python.
step 1
install fpdf
pip install fpdf
step 2
You need to create a TXT file for testing
Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum has been the
industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and
scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap
into electronic typesetting, remaining essentially
unchanged. It was popularised in the 1960s with the
release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software
like Aldus PageMaker including versions of Lorem Ipsum.
step 3
Add PDF file setting
from fpdf import FPDF
pdf = FPDF()
pdf.add_page()
pdf.set_font("Arial", size = 10)
step 4
Read all text from the TXT file
for word in open('my_txt_file.txt', 'r'):
pdf.cell(200, 20, txt = word, ln = 1, align = 'L')
pdf.output('my_pdf_file.pdf')
result
Now we're done π€
Don't forget to like and follow π
Support me on PayPal π€
https://www.paypal.com/paypalme/amr396
Top comments (0)