惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

大猫的无限游戏
大猫的无限游戏
aimingoo的专栏
aimingoo的专栏
I
InfoQ
B
Blog RSS Feed
D
DataBreaches.Net
S
SegmentFault 最新的问题
P
Proofpoint News Feed
A
About on SuperTechFans
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
小众软件
小众软件
博客园 - Franky
有赞技术团队
有赞技术团队
D
Docker
T
Tailwind CSS Blog
雷峰网
雷峰网
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Blog — PlanetScale
Blog — PlanetScale
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog
V
Visual Studio Blog
宝玉的分享
宝玉的分享
爱范儿
爱范儿

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Renaming 200 PDFs by Their Content — Without an LLM
hiyoyo · 2026-04-27 · via DEV Community
Cover image for Renaming 200 PDFs by Their Content — Without an LLM

hiyoyo

All tests run on an 8-year-old MacBook Air.

"scan_20260101_0042.pdf" tells you nothing.

Smart Rename reads the first page of each PDF and generates a meaningful filename. No API call, no LLM, no internet. Just heuristics and pattern matching in Rust.


What the first page usually contains

Most documents put identifying information near the top: document type, date, recipient, reference number. The challenge is extracting it reliably across wildly different layouts.

pub fn extract_rename_candidates(doc: &Document) -> RenameCandidates {
    let first_page_text = doc.extract_text(&[1]).unwrap_or_default();
    let lines: Vec<&str> = first_page_text.lines()
        .map(str::trim)
        .filter(|l| !l.is_empty())
        .collect();

    RenameCandidates {
        title: "find_title(&lines),"
        date: find_date(&lines),
        doc_type: classify_document(&lines),
        reference: find_reference_number(&lines),
    }
}

Enter fullscreen mode Exit fullscreen mode


Date extraction

Dates appear in many formats. Regex covers the common ones:

pub fn find_date(lines: &[&str]) -> Option {
    let patterns = [
        r"(\d{4})[年/\-\.](\d{1,2})[月/\-\.](\d{1,2})[日]?",
        r"(\d{1,2})[/\-\.](\d{1,2})[/\-\.](\d{4})",
        r"(January|February|March|April|May|June|July|August|September|October|November|December)\s+\d{1,2},?\s+\d{4}",
    ];

    for line in lines {
        for pattern in &patterns {
            if let Some(cap) = Regex::new(pattern).unwrap().captures(line) {
                return Some(normalize_date(&cap));
            }
        }
    }
    None
}

Enter fullscreen mode Exit fullscreen mode


Document type classification

A small keyword list covers most business documents:

pub fn classify_document(lines: &[&str]) -> &'static str {
    let text = lines.join(" ").to_lowercase();

    if text.contains("invoice") || text.contains("請求書") { return "invoice"; }
    if text.contains("contract") || text.contains("契約書") { return "contract"; }
    if text.contains("receipt") || text.contains("領収書") { return "receipt"; }
    if text.contains("report") || text.contains("報告書") { return "report"; }
    if text.contains("minutes") || text.contains("議事録") { return "minutes"; }

    "document"
}

Enter fullscreen mode Exit fullscreen mode


Output

scan_20260101_0042.pdf  →  20260115_invoice_ABC-Corp.pdf
doc_final_v3.pdf        →  20260203_contract_NDA.pdf
untitled.pdf            →  20260310_report.pdf

Enter fullscreen mode Exit fullscreen mode

Not perfect. Works well enough that users stop caring about the originals.


Hiyoko PDF Vault → https://hiyokoko.gumroad.com/l/HiyokoPDFVault
X → @hiyoyok