Giter Site home page Giter Site logo

tkpdfviewer's People

Contributors

roshanpaswan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

tkpdfviewer's Issues

Deprecation Warning

Hi! I'm encountering two deprecation warnings while using your library:

Deprecation: 'getPixmap' removed from class 'Page' after v1.19 - use 'get_pixmap'.
Deprecation: 'getImageData' removed from class 'Pixmap' after v1.19 - use 'tobytes'

Could you please solve this?

Anyway, thanks for your hard work ๐Ÿ’ช

Open multiple files

When I try to open multiple files in different ShowPdf instances, I get a concatenation of both documents in both frames. I would expect instead to get each document in a separate frame.

Code to reproduce the issue:

from tkPDFViewer import tkPDFViewer as pdf
from tkinter import Tk

root = Tk()

file1 = "/path/to/first/pdf"
file2 = "/path/to/second/pdf"

viewer1 = pdf.ShowPdf()
pdf_frame1 = viewer1.pdf_view(root, pdf_location=file1, width=150,height=50)
pdf_frame1.pack(side="left")
viewer2 = pdf.ShowPdf()
pdf_frame2 = viewer2.pdf_view(root, pdf_location=file2, width=150,height=50)
pdf_frame2.pack(side="left")
root.mainloop()

I know what is causing the issue (the img_object_li class attribute) and I will work on a fix on my fork of this project.

Imrpovement

Hello,
I would like to offer you some improvements

`

class ShowPdf(threading.Thread, Frame):

img_object_li = []

def __init__(self, parent, width=1200, height=600, pdf_location="", bar=True, load="after"):
    threading.Thread.__init__(self)
    Frame.__init__(self, parent, width=width, height=height, bg="white")

    self.__flagKill = False
    self.__flagRefresh = True

    self.pdf_location = pdf_location
    self.bar = bar
    self.load = load

    scroll_y = Scrollbar(self, orient="vertical")
    scroll_x = Scrollbar(self, orient="horizontal")

    scroll_x.pack(fill="x", side="bottom")
    scroll_y.pack(fill="y", side="right")

    self.percentage_load = StringVar()

    if self.bar == True and self.load == "after":
        self.display_msg = Label(self, textvariable=self.percentage_load)
        self.display_msg.pack(pady=10)

        self.loading = Progressbar(self, orient=HORIZONTAL, length=100, mode='determinate')
        self.loading.pack(side=TOP, fill=X)

    self.text = Text(self, yscrollcommand=scroll_y.set, xscrollcommand=scroll_x.set, width=width, height=height)
    self.text.pack(side="left")

    scroll_x.config(command=self.text.xview)
    scroll_y.config(command=self.text.yview)

def run(self):
    while self.__flagKill is False:
        if self.__flagRefresh is True:
            precentage_dicide = 0

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

            index = 1.0
            self.text.configure(state='normal')
            for i in self.img_object_li:
                self.text.image_create(index, image=i)
                self.text.insert(index, "\n\n")
                self.text.image = i  #Very important, otherwise the thread gets blocked
                index += 1
            self.text.configure(state="disabled")
            self.img_object_li.clear()  #Avoid duplicates
            self.__flagRefresh = False

def refresh(self):
    self.__flagRefresh = True

def stop(self):
    self.__flagKill = True

`

If you want to add a pdf afterwards, you have to make these modifications:

`

            self.text.configure(state='normal')
            for i in self.img_object_li:
                self.text.image_create(END, image=i)
                self.text.insert(END, "\n\n")
                self.text.image = i  #Very important, otherwise the thread gets blocked
            self.text.configure(state="disabled")
            self.img_object_li.clear()  #Avoid duplicates
            self.__flagRefresh = False

def add_pdf(self, pdf_location):
    self.pdf_location = pdf_location
    self.__flagRefresh = True

`

Example of use:

`

self.pdfView = obdoTkShowPDF(self, pdf_location=pathPDF, width=50, height=30)
self.pdfView.grid(row=1, column=1)
self.pdfView.start()
#do stuff
self.pdfView.stop()
self.pdfView.join()

`

name 'Progressbar' is not defined

I write your code and get an error
the error is :
This error occured while importing neccesary modules or library No module named 'frontend'
Traceback (most recent call last):
File "C:\Users\jotha\AppData\Local\Programs\Python\Python310\lib\code.py", line 90, in runcode
exec(code, self.locals)
File "", line 1, in
File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.1.3\plugins\python-ce\helpers\pydev_pydev_bundle\pydev_umd.py", line 198, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.1.3\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "D:/Programe_Project/python/pdfPreview/pdfPreview.py", line 33, in
variable2 = variable1.pdf_view(root,pdf_location=r"location",width=50,height=100)
File "C:\Users\jotha\AppData\Local\Programs\Python\Python310\lib\site-packages\tkPDFViewer\tkPDFViewer.py", line 31, in pdf_view
loading = Progressbar(self.frame,orient= HORIZONTAL,length=100,mode='determinate')
NameError: name 'Progressbar' is not defined
............................................................................................
I installed all Dependencies

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.