I'm currently using pdf2image - a poppler wrapper- to convert a pdf into pillow images so I can view the pdf. However, no matter what pdf I use, I always get this following error:
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
Is there any way to fix this short of changing the specs on my computer or getting a new one? Here's my code:
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()
Any help would be greatly appreciated.
Just batch convert the PDF in batches of say 5 each time. i.e.,
from pdf2image import pdfinfo_from_path,convert_from_path
info = pdfinfo_from_path(pdf_file, userpw=None, poppler_path=None)
maxPages = info["Pages"]
for page in range(1, maxPages+1, 10) :
convert_from_path(pdf_file, dpi=200, first_page=page,