54 lines
1.3 KiB
Python
54 lines
1.3 KiB
Python
import argparse
|
|
import pymupdf
|
|
|
|
import tkinter
|
|
from tkinter import ttk
|
|
from PIL import Image, ImageTk
|
|
|
|
CURRENT_PAGE = 0
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("file")
|
|
args = parser.parse_args()
|
|
|
|
doc: pymupdf.Document
|
|
with pymupdf.open(args.file) as doc:
|
|
root = tkinter.Tk()
|
|
frm = ttk.Frame(root, padding=10)
|
|
frm.grid()
|
|
|
|
label = ttk.Label(frm)
|
|
label.grid(column=1, row=0)
|
|
|
|
def load_page(i: int):
|
|
page = doc[i]
|
|
pix = page.get_pixmap()
|
|
|
|
mode = "RGBA" if pix.alpha else "RGB"
|
|
img = Image.frombytes(mode, [pix.width, pix.height], pix.samples)
|
|
img = ImageTk.PhotoImage(img)
|
|
label.configure(image=img)
|
|
label.image = img
|
|
|
|
def next_page():
|
|
global CURRENT_PAGE
|
|
CURRENT_PAGE += 1
|
|
load_page(CURRENT_PAGE)
|
|
|
|
def previous_page():
|
|
global CURRENT_PAGE
|
|
CURRENT_PAGE -= 1
|
|
load_page(CURRENT_PAGE)
|
|
|
|
ttk.Button(frm, text="Previous", command=previous_page).grid(column=0, row=0)
|
|
ttk.Button(frm, text="Next", command=next_page).grid(column=2, row=0)
|
|
|
|
load_page(CURRENT_PAGE)
|
|
|
|
root.mainloop()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|