Djnago:How to generate a pdf file

Solution for Djnago:How to generate a pdf file
is Given Below:

i want to generate a pdf file containing the OCR result of an uploaded image, but i can’t seem to figure out how.
when i store the result in a txt file it works but every pdf i create is corrupted.
i used FPDF to create the pdf but it’s not working.

if : #this here to see if there is an image upload in order to generate the file
            c="".join(random.SystemRandom().choice(string.ascii_letters + string.digits) for _ in range(10))
            pdf = FPDF(format="A4")
            pdf.set_font("Arial", size=12)
            for x in file.readlines():
                pdf.cell(0,7, txt=x, ln=1)

the create_Pdf function is just a function where i run pytesseract on the image and it just returns txt