UniPagePDF

How to Batch Rename PDF Files Based on Content

Office workers, finance teams, and HR personnel often have to handle dozens or hundreds of PDFs named with random codes or numbers (e.g. invoices, receipts, resumes). Manually opening, copying internal text, and renaming each file is inefficient. This guide demonstrates how to build a simple automation script in Python, and introduces a zero-code online alternative for instant batch renaming.

Method 1: Automating with a Python Script

If you are comfortable running commands in a terminal environment, using Python with a third-party library like pypdf allows you to quickly query internal text data and modify file attributes:

  1. Open your terminal or command prompt window and run the package installer command:
    pip install pypdf
  2. Create a script file named rename_pdfs.py and add the following template:
    import os
    from pypdf import PdfReader
    
    def batch_rename(directory_path):
        for filename in os.listdir(directory_path):
            if filename.endswith(".pdf"):
                full_path = os.path.join(directory_path, filename)
                try:
                    reader = PdfReader(full_path)
                    # Read the character text stream from Page 1
                    text = reader.pages[0].extract_text()
                    lines = [line.strip() for line in text.split('\n') if line.strip()]
                    
                    if lines:
                        # Choose the first non-empty text string as candidate name
                        clean_name = lines[0][:50]
                        # Scrub invalid characters to satisfy standard operating system requirements
                        for char in ['/', '\\', ':', '*', '?', '"', '<', '>', '|']:
                            clean_name = clean_name.replace(char, '_')
                        
                        new_filename = f"{{clean_name}}.pdf"
                        new_path = os.path.join(directory_path, new_filename)
                        os.rename(full_path, new_path)
                        print(f"Renamed: {{filename}} -> {{new_filename}}")
                except Exception as e:
                    print(f"Error parsing {{filename}}: {{e}}")
    
    # Provide your folder location and run the script
    batch_rename("./invoice_directory")
  3. Run the script in your terminal to process and update the file tags.

Alternative Option: Use UniPagePDF Smart Batch Renamer

If you do not want to set up local environments or manage terminal processes, UniPagePDF provides a zero-code graphical alternative. The software parses files purely locally inside your browser sandbox, keeping your documents confidential:

  1. Drag and drop your PDF collection into the UniPagePDF batch workspace.
  2. The application scans the text content of your documents locally, instantly extracting candidate names in an easy-to-read table.
  3. Quickly inspect and manually correct names directly in the grid.
  4. Click download to save all renamed PDFs inside a neat ZIP package.
Start Batch Renaming PDFs