-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathview_pdf.py
More file actions
80 lines (62 loc) · 2.53 KB
/
view_pdf.py
File metadata and controls
80 lines (62 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
try:
from tkinter import*
import fitz
from tkinter.ttk import Progressbar
from threading import Thread
import math
except Exception as e:
print(f"This error occured while importing neccesary modules or library {e}")
class ShowPdf():
img_object_li = []
def __init__(self):
self.zoom()
def zoom(self):
self.zoom_x = 1.5
self.zoom_y = 1.5
self.pdx=300
def zoom_in(self):
self.zoom_x=self.zoom_x+0.1
self.zoom_y=self.zoom_y+0.1
self.pdx=self.pdx-30
def zoom_out(self):
if self.zoom_x==1.3 or self.zoom_y==1.0:
return True
else:
self.zoom_x=self.zoom_x-0.1
self.zoom_y=self.zoom_y-0.1
self.pdx=self.pdx+30
return False
def pdf_is_encrypted(self,pdf_location):
pdf = fitz.Document(pdf_location)
return pdf.isEncrypted
def pdf_view(self,master,width=1200,height=600,bar=True,load="after", pdf_location="",password=None):
self.pdf_location=pdf_location
frame = Frame(master,width= width,height= height,bg="white")
scroll_y = Scrollbar(frame,orient="vertical")
scroll_x = Scrollbar(frame,orient="horizontal")
scroll_x.pack(fill="x",side="bottom")
scroll_y.pack(fill="y",side="right")
self.text = Text(frame,yscrollcommand=scroll_y.set,xscrollcommand= scroll_x.set,padx=self.pdx,width= width,height= height)
self.text.pack(side="left")
scroll_x.config(command=self.text.xview)
scroll_y.config(command=self.text.yview)
def add_img():
if password is not None:
open_pdf = fitz.Document(pdf_location)
open_pdf.authenticate(password)
else:
open_pdf = fitz.open(self.pdf_location)
pdf_img=[]
for page in open_pdf:
mat = fitz.Matrix(self.zoom_x,self.zoom_y)
pix = page.getPixmap(matrix=mat)
pix1 = fitz.Pixmap(pix,0) if pix.alpha else pix
img = pix1.getImageData("ppm")
timg = PhotoImage(data = img)
self.img_object_li.append(timg)
pdf_img.append(timg)
for i in pdf_img:
self.text.image_create("1.6",image=i)
self.text.insert(END,"\n\n")
add_img()
return frame