Initial
Just browses through PDF pages
This commit is contained in:
		
						commit
						b774b90504
					
				
					 2 changed files with 55 additions and 0 deletions
				
			
		
							
								
								
									
										2
									
								
								requirements.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								requirements.txt
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,2 @@ | ||||||
|  | pillow==10.4.0 | ||||||
|  | PyMuPDF==1.24.9 | ||||||
							
								
								
									
										53
									
								
								src/main.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								src/main.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -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() | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue