From b774b90504fdc7bc7c32d4f7d51fff9123de73c2 Mon Sep 17 00:00:00 2001 From: Rahix Date: Mon, 19 Aug 2024 02:25:31 +0200 Subject: [PATCH] Initial Just browses through PDF pages --- requirements.txt | 2 ++ src/main.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 requirements.txt create mode 100644 src/main.py diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..9b04683 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pillow==10.4.0 +PyMuPDF==1.24.9 diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..0e5e7a0 --- /dev/null +++ b/src/main.py @@ -0,0 +1,53 @@ +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()