roshanpaswan / tkpdfviewer Goto Github PK
View Code? Open in Web Editor NEWThe tkPDFViewer is python library developed by Roshan Paswan, which allows you to embed the PDF file in your tkinter GUI.
License: MIT License
The tkPDFViewer is python library developed by Roshan Paswan, which allows you to embed the PDF file in your tkinter GUI.
License: MIT License
Is there a way to use the library with an application written using grid manager?
Update - I just cloned this, made changes pushed by @brotherrobot, and created a pypi package called tkPDFViewer2. Feel free to download. I can remove this if @Roshanpaswan ever becomes active again.
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
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.
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()
`
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.