| 12345678910111213141516171819202122232425 |
- # -*- coding: utf-8 -*-
- """扫描 PDF 中内容过少(大片空白)的页面。"""
- import io
- import os
- import sys
- import fitz
- sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
- PDF = os.path.join(os.path.dirname(os.path.abspath(__file__)),
- "_tmp_inspect", "current.pdf")
- d = fitz.open(PDF)
- bad = []
- for i, pg in enumerate(d, 1):
- txt = pg.get_text().strip()
- # 页码本身算 2~4 个字符,先去掉
- nchar = len(txt.replace("\n", ""))
- nimg = len(pg.get_images(full=True))
- if nimg == 0 and nchar < 90:
- bad.append((i, nchar, txt.replace("\n", " / ")[:70]))
- print(f"共 {d.page_count} 页;内容过少的页 {len(bad)} 页")
- for i, n, t in bad:
- print(f" p{i:>3} {n:>3} 字 「{t}」")
- d.close()
|