Python-将PDF文件保存到磁盘

时间:2019-06-17 06:46:04

标签: python python-3.x python-2.7 pdf

我有下面的代码在内存中创建一个pdf文件。

 pdf = pytesseract.image_to_pdf_or_hocr(self.main_window.filename, extension='pdf')

我想将该pdf文件保存在磁盘中,以便查看。我将如何在python中做到这一点?

1 个答案:

答案 0 :(得分:1)

如果type(pdf)的类型为<class 'bytes'>,则可以执行以下操作:

with open('yourfile.pdf', 'wb') as f:
    f.write(pdf)
相关问题