@@ -498,6 +498,26 @@ def _update_output_suggestion(self):
498498
499499 self ._update_label (self .output_label , self .output_path , active = True )
500500
501+ def _get_pdf_page_count (self , filename ):
502+ """Get the total number of pages in a PDF file."""
503+ doc = fitz .open (filename )
504+ total_pages = len (doc )
505+ doc .close ()
506+ return total_pages
507+
508+ def _load_input_pdf (self , filename ):
509+ """Load input PDF and update UI with file information."""
510+ total_pages = self ._get_pdf_page_count (filename )
511+
512+ self .input_path = filename
513+ self ._update_label (self .input_label , filename , active = True )
514+ self .page_info_label .setText (f"Total pages: { total_pages } " )
515+
516+ # Auto-suggest output path
517+ self ._update_output_suggestion ()
518+
519+ self .process_button .setEnabled (True )
520+
501521 def browse_input (self ):
502522 filename , _ = QFileDialog .getOpenFileName (
503523 self , "Select Input PDF" , "" , "PDF files (*.pdf);;All files (*.*)"
@@ -507,18 +527,7 @@ def browse_input(self):
507527 return
508528
509529 try :
510- doc = fitz .open (filename )
511- total_pages = len (doc )
512- doc .close ()
513-
514- self .input_path = filename
515- self ._update_label (self .input_label , filename , active = True )
516- self .page_info_label .setText (f"Total pages: { total_pages } " )
517-
518- # Auto-suggest output path
519- self ._update_output_suggestion ()
520-
521- self .process_button .setEnabled (True )
530+ self ._load_input_pdf (filename )
522531 except Exception as e :
523532 QMessageBox .critical (self , "Error" , f"Could not read PDF: { str (e )} " )
524533 self .input_path = None
@@ -563,9 +572,8 @@ def process_pdf(self):
563572 raise ValueError (f"Invalid input:\n { str (e )} " ) from e
564573
565574 # Check for file overwrites using mode-specific checker
566- if self .current_mode .check_overwrite_func (self .output_path , parsed_input ):
567- if not self ._confirm_overwrite ():
568- return
575+ if self .current_mode .check_overwrite_func (self .output_path , parsed_input ) and not self ._confirm_overwrite ():
576+ return
569577
570578 # Execute the core PDF manipulation function
571579 message = self .current_mode .core_func (self .input_path , parsed_input , self .output_path )
0 commit comments