如何将字节字符串转换为文本文件?

时间:2019-04-04 06:07:37

标签: python bytestring pypdf2 stringio

我正在尝试运行此代码。它给了我以字节为单位的输出。我想知道如何将字节转换为文本文件

def convert(fname,pages):
    if not pages:
        pagenums = set()
    else:
        pagenums = set(str(pages))

    output = StringIO()
    manager = PDFResourceManager()
    converter = TextConverter(manager, output, laparams=LAParams())
    interpreter = PDFPageInterpreter(manager, converter)

    infile = open(fname, 'rb')
    for page in PDFPage.get_pages(infile):
        interpreter.process_page(page)
    infile.close()
    converter.close()
    text = output.getvalue()
    output.close
    return text

0 个答案:

没有答案