AttributeError: 'Page' object has no attribute 'getPixmap'

I was trying to code a pdf reader and I got this Error!!! Any Ideas?

from tkinter import * 
from tkinter import filedialog
from tkPDFViewer import tkPDFViewer as pdf
import os

the_prog = Tk()
the_prog.title("PDF Viewer")
the_prog.geometry("500x650+550+100")
the_prog.resizable(False, False)
the_prog.configure(background='white')

def open_dir():  #The function used to open the file where I can't find the error!
    the_file = filedialog.askopenfilename(initialdir=os.getcwd(), title ="Choose the PDF File", filetype=(("PDF File",".pdf"),("PDF File","pdf"), 
    ("PDF File", "PDF")))
    
    show_file = pdf.ShowPdf() 
    show_pdf = show_file.pdf_view(the_prog, pdf_location=open(the_file,'r'), width=77,height=100)
    show_pdf.pack(pady=(0,0))

choose_button= Button(the_prog, text = "Choose the pdf File", width = "50", font= ("Arial","15"),fg = "white",bg = "red", cursor = "hand2", command = open_dir)
choose_button.pack()

folder_image = PhotoImage(file="Image1.png")
background_photo = Label(the_prog, image=folder_image, width=300, height=300 )
background_photo.place(x=100, y=150)

under_text = Label(the_prog, text= "Thank you for choosing us.", font= "Arial")
under_text.place(x=160,y=550)
under_text2 = Label(the_prog, text= "®Ammar Howeka", font=('Arial','10'))
under_text2.place(x=380,y=620)

the_prog.mainloop()

You have not included the traceback, without that we can not be sure what is wrong.

1 Like

Here is the traceback:

Traceback (most recent call last):
  File "C:\Users\Momento\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\Momento\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Momento\AppData\Local\Programs\Python\Python38\lib\site-packages\tkPDFViewer\tkPDFViewer.py", line 46, in add_img
    pix = page.getPixmap()
AttributeError: 'Page' object has no attribute 'getPixmap'```

I tried to install tkPDFViewer and see that it want to run setup.py.
I’m not willing to let it do that.

I also see that its not been updated for any release since 3.6 and in Jan 1 2021.

This looks to be an abandon package maybe look for a support one?

1 Like

Is there activity on the github repo?

When I face such issues, I just try to look for an alternative if downgrading doesn’t work as well.

1 Like

So we can say that: package issue and there is no any solution?

For now yes, one solution is to try to fix it yourself but that will require considerable time and effort.

1 Like

I had the same problem few days ago and i found the solution. I edit the Funktion add_img because there was a mistake with the ussage of the fitz Libary Here is my code:

 def add_img():
            precentage_dicide = 0
            open_pdf = fitz.open(pdf_location)

            for page in open_pdf:
                pix = page.get_pixmap()
                pix1 = fitz.Pixmap(pix,0) if pix.alpha else pix
                img = pix1.tobytes("ppm")
                timg = PhotoImage(data = img)
                self.img_object_li.append(timg)
                if bar==True and load=="after":
                    precentage_dicide = precentage_dicide + 1
                    percentage_view = (float(precentage_dicide)/float(len(open_pdf))*float(100))
                    loading['value'] = percentage_view
                    percentage_load.set(f"Please wait!, your pdf is loading {int(math.floor(percentage_view))}%")
            if bar==True and load=="after":
                loading.pack_forget()
                self.display_msg.pack_forget()

            for i in self.img_object_li:
                self.text.image_create(END,image=i)
                self.text.insert(END,"\n\n")
            self.text.configure(state="disabled")
1 Like

can you please explain more and write the code including mine as i’ve issue with fitz

There is nothing wrong with your Code, the Libary has 2 Issues. Swap the Funktion add_img in the file C:\Users\Momento\AppData\Local\Programs\Python\Python38\lib\site-packages\tkPDFViewer\tkPDFViewer.py with the Code in my previous post

1 Like

I am having de same issue using tkPDFViewer library. here the error im getting AppData\Local\Programs\Python\Python310\lib\site-packages\tkPDFViewer\tkPDFViewer.py", line 46, in add_img pix = page.getPixmap() AttributeError: 'Page' object has no attribute 'getPixmap'. Did you mean: 'get_pixmap'? well, then if i change getPixmap to get_pixmap I get the following error:

`AppData\Local\Programs\Python\Python310\lib\site
packages\tkPDFViewer\tkPDFViewer.py", line 48, in 
add_imgimg = pix1.getImageData("ppm")
AttributeError: 'Pixmap' object has no attribute 'getImageData'`

A lot of people need some help from tkPDFViewer’s owner. but what I want is, pip community have to delete this tkPDFViewer library, because it has no a preview version, it is the only version the owner release, then if the very first release doesn’t work, it means the owner have not tested his code before pushing it into production. the owner should have specified versions for any change made in the code rather than pushing the code in differing method to bypass pip version controller. and that change of GETPIXMAP should be considered as mayor change of version. here I’m using the library:

`# Importing tkinter to make gui in python

from tkinter import*

# Importing tkPDFViewer to place pdf file in gui.
# In tkPDFViewer library there is
# an tkPDFViewer module. That I have imported as pdf

from tkPDFViewer import tkPDFViewer as pdf

# Initializing tk

root = Tk()

# Set the width and height of our root window.

root.geometry("550x750")

# creating object of ShowPdf from tkPDFViewer.

v1 = pdf.ShowPdf()

# Adding pdf location and width and height.

v2 = v1.pdf_view(root,pdf_location = r"simplepdf.pdf",width = 
50,height = 100)

# Placing Pdf in my gui.

v2.pack()

root.mainloop()`
1 Like

What is the Funktion?