#StackBounty: #python #pdf #memory #memory-management #poppler How to stop Memory Error in python for pdf conversion?

Bounty: 50

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:UserskareeAppDataLocalProgramsPythonPython39-32libthreading.py", line 954, in _bootstrap_inner
    self.run()
  File "C:UserskareeAppDataLocalProgramsPythonPython39-32libthreading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "C:UserskareeAppDataLocalProgramsPythonPython39-32libsubprocess.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.0Librarybin")
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, 'nn')
mainloop()

Any help would be greatly appreciated.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.