【发布时间】:2021-06-26 13:50:45
【问题描述】:
我目前正在使用 pdf2image - 一个 poppler 包装器 - 将 pdf 转换为枕头图像,以便我可以查看 pdf。但是,无论我使用什么 pdf,我总是会收到以下错误:
Traceback (most recent call last):
File "C:\Users\karee\AppData\Local\Programs\Python\Python39-32\lib\threading.py", line 954, in _bootstrap_inner
self.run()
File "C:\Users\karee\AppData\Local\Programs\Python\Python39-32\lib\threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\karee\AppData\Local\Programs\Python\Python39-32\lib\subprocess.py", line 1479, in _readerthread
buffer.append(fh.read())
MemoryError
除了更改我的计算机规格或购买新的规格之外,有什么办法可以解决这个问题吗? 这是我的代码:
root = Tk()
pdf_frame = Frame(root).pack(fill=BOTH, expand=1)
scrol_y = Scrollbar(pdf_frame, orient=VERTICAL)
pdf = Text(pdf_frame, yscrollcommand=scrol_y.set, bg="grey")
scrol_y.pack(side=RIGHT, fill=Y)
scrol_y.config(command=pdf.yview)
pdf.pack(fill=BOTH, expand=1)
pages = convert_from_path('Books/Keeper Of The Lost Cities/Everblaze ( PDFDrive ).pdf', size=(800, 900),
poppler_path=r"poppler-21.03.0\Library\bin")
photos = []
for i in range(len(pages)):
photos.append(ImageTk.PhotoImage(pages[i]))
for photo in photos:
pdf.image_create(END, image=photo)
pdf.insert(END, '\n\n')
mainloop()
任何帮助将不胜感激。
【问题讨论】:
-
你的内存有多大?当你运行这个程序时,你的 ram 使用情况如何?有问题的文件有多大?
-
@wxz 我有 24GB 的 ram,我不知道 ram 的使用情况,文件很长,有几百页
-
@KJ 我想在 Python 中创建一个 PDF 查看器,我发现这样做的方法是使用 pdf2image 并将其转换为 PIL 图像。你能告诉我如何将它批处理成我会这样做的集合吗?
标签: python pdf memory memory-management poppler