📄

Đổi tên PDF theo nội dung

Tự động đọc nội dung file PDF (như số hóa đơn, tên khách hàng) để đổi tên file hàng loạt.

Document ⭐⭐⭐ Advanced ⏱️ 10 phút

😫 Vấn đề (The Pain Point)

Kế toán tải về 100 file hóa đơn điện tử. Tên file toàn là mã ngẫu nhiên INV_002391238.pdf. Bạn cần đổi tên thành Hoadon_Vinamilk_Soluong10.pdf để dễ tìm. Mở từng file lên -> Xem nội dung -> Rename. Mất cả buổi chiều!

🚀 Giải pháp Agentic (The Solution)

Tool “đọc hiểu” file PDF, tìm dòng chữ bạn cần (bằng quy tắc Regex) và dùng nó làm tên file.

Tính năng:

  • Keyword Extraction: Tìm chuỗi sau chữ “Khách hàng:” hoặc “Số hóa đơn:”.
  • Pattern Matching: Tự động bắt pattern ngày tháng, mã số thuế.
  • Review Mode: Hiện tên cũ và tên mới dự kiến để bạn check trước khi đổi.

PDF Rename Screenshot

🤖 Engineering Prompt (Copy & Paste)

**Role:** Python Automation Developer

**Task:** Create a "Content-based PDF Renamer".

**Requirements:**
1.  **Tech Stack:** Python, `tkinter`, `pypdf` (extract text), `re` (regex).
2.  **GUI:**
    *   Select Source Folder.
    *   **Pattern Config:**
        *   Input Regex Pattern (e.g., `Invoice No: (\d+)`).
        *   Template for new name (e.g., `Invoice_{1}.pdf`).
    *   **Preview Table (Important):** Show Filename | Extracted Text | New Filename.
    *   "Rename All" button.
3.  **Logic:**
    *   Extract text from first page of PDF.
    *   Search for regex pattern.
    *   If match found, generate new name.
    *   Handle duplicate names.
4.  **Deliverables:**
    *   `smart_rename.py`
    *   `run.bat`
    *   `requirements.txt`

**Context:** Accountants extracting invoice numbers from filenames.

🧠 Giải mã Prompt

  • Regex (Regular Expression): Ngôn ngữ tìm kiếm mẫu nâng cao. Ví dụ (\d+) nghĩa là “tìm một dãy số”. Prompt này yêu cầu GUI cho phép nhập Regex giúp tool áp dụng được cho mọi loại hóa đơn khác nhau.
  • Preview Table: Cực kỳ quan trọng. AI có thể nhận diện sai, nên Human phải được xem trước kết quả đổi tên.

🛠️ Hướng dẫn

  1. Copy Prompt -> Paste -> Chạy.
  2. Nhập Pattern (Ví dụ: Số: (\d+) để lấy số hóa đơn).
  3. Bấm Analyze để xem thử -> Rename để chốt.

Workflows liên quan

Khám phá danh mục khác

📬

Get Started with Agentic Working

Subscribe to receive updates from AgenticWorking.io

📖 Free eBook Guide 📦 7 Ready-to-use Scripts 🔔 Weekly Tips

No spam, unsubscribe anytime. Join 1,000+ subscribers.