1

I have a script that writes into a text file and places it on my local drive. Does python have any library or scripts that can take that text file and convert into a PDF?

Im using report lab below but i am getting an error: AttributeError: module 'reportlab.pdfgen.canvas' has no attribute 'drawString'

ptr = open(out_file, "r")  # text file I need to convert
    lineas = ptr.readlines()
    ptr.close()
    i = 750
    numeroLinea = 0

    while numeroLinea < len(lineas):
        if numeroLinea - len(lineas) < 60:  # I'm gonna write every 60 lines because I need it like that
            i = 750
            for linea in lineas[numeroLinea:numeroLinea + 60]:
                canvas.drawString(15, i, linea.strip())
                numeroLinea += 1
                i -= 12
            canvas.showPage()
        else:
            i = 750
            for linea in lineas[numeroLinea:]:
                canvas.drawString(15, i, linea.strip())
                numeroLinea += 1
                i -= 12
            canvas.showPage()
ajburnett344
  • 79
  • 1
  • 9

1 Answers1

1

I think what you're looking for is the PyPDF2 library:

Rayan Hatout
  • 640
  • 5
  • 22