How to convert Cyrillic UTF-8 .txt file to PDF file by Python?
Because i tried so many stackoverflow answers but it doesn't work
Please help me any recent method to answer my question?
CodePudding user response:
Try this:
https://www.geeksforgeeks.org/convert-text-and-text-file-to-pdf-using-python/
# Python program to convert
# text file to pdf file
from fpdf import FPDF
# save FPDF() class into
# a variable pdf
pdf = FPDF()
# Add a page
pdf.add_page()
# set style and size of font
# that you want in the pdf
pdf.set_font("Arial", size = 15)
# open the text file in read mode
f = open("myfile.txt", "r")
# insert the texts in pdf
for x in f:
pdf.cell(200, 10, txt = x, ln = 1, align = 'C')
# save the pdf with name .pdf
pdf.output("mygfg.pdf")
CodePudding user response:
It will be easier to install ready made python lib ‘txt2pdf' if you are looking for a simple route to follow. GitHub Link