Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中将文本文件转换为PDF_Python - Fatal编程技术网

在Python中将文本文件转换为PDF

在Python中将文本文件转换为PDF,python,Python,我有一个脚本,可以写入文本文件并将其放在本地驱动器上。python是否有任何库或脚本可以将该文本文件转换为PDF格式 我正在使用下面的report lab,但收到一个错误:AttributeError:module'reportlab.pdfgen.canvas'没有属性'drawString' ptr = open(out_file, "r") # text file I need to convert lineas = ptr.readlines() ptr.close()

我有一个脚本,可以写入文本文件并将其放在本地驱动器上。python是否有任何库或脚本可以将该文本文件转换为PDF格式

我正在使用下面的report lab,但收到一个错误:AttributeError:module'reportlab.pdfgen.canvas'没有属性'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()
ptr=open(out_file,“r”)#我需要转换的文本文件
lineas=ptr.readlines()
ptr.close()
i=750
numeroLinea=0
当numeroLinea
我想您要找的是PyPDF2库:


可能的副本是PDF到文本。我正在寻找PDF文本。是的,我编辑了链接..其他可能的副本:@YatishKadam我在报告实验室“AttributeError:module'reportlab.pdfgen.canvas'没有属性'drawString'时出错”