-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheee.py
72 lines (56 loc) · 1.79 KB
/
eee.py
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
import fitz
from tkinter import *
from PIL import Image, ImageTk
# open pdf file
file_name = r"C:\Users\alber\Documents\LabMax\Paluh\Currículos Lattes - Albert França Josuá Costa.pdf"
doc = fitz.open(file_name)
# transformation matrix we can apply on pages
zoom = 1.5
mat = fitz.Matrix(zoom, zoom)
# count number of pages
num_pages = 0
for p in doc:
num_pages += 1
# initialize and set screen size
root = Tk()
root.geometry('750x700')
# add scroll bar
scrollbar = Scrollbar(root)
scrollbar.pack(side = RIGHT, fill = Y)
# add canvas
canvas = Canvas(root, yscrollcommand = scrollbar.set)
canvas.pack(side = LEFT, fill = BOTH, expand = 1)
# define entry point (field for taking inputs)
entry = Entry(root)
# add a label for the entry point
label = Label(root, text="Enter page number to display:")
def pdf_to_img(page_num):
page = doc.load_page(page_num)
pix = page.get_pixmap(matrix=mat)
return Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
def show_image():
try:
page_num = int(entry.get()) - 1
assert page_num >= 0 and page_num < num_pages
im = pdf_to_img(page_num)
img_tk = ImageTk.PhotoImage(im)
frame = Frame(canvas)
panel = Label(frame, image=img_tk)
panel.pack(side="bottom", fill="both", expand="yes")
frame.image = img_tk
canvas.create_window(0, 0, anchor='nw', window=frame)
frame.update_idletasks()
canvas.config(scrollregion=canvas.bbox("all"))
except:
pass
# add button to display pages
button = Button(root, text="Show Page", command=show_image)
# set visual locations
label.pack(side=TOP, fill=None)
entry.pack(side=TOP, fill=BOTH)
button.pack(side=TOP, fill=None)
entry.insert(0, '1')
show_image()
scrollbar.config(command = canvas.yview)
root.mainloop()
doc.close()