# -*- coding: utf-8 -*- """列出每页倒数第二行(章节名)与重点页原文""" import fitz, re doc = fitz.open(r'E:/cfc/docs/参考资料/560822024-张学红.pdf') print('===== 每页章节名(倒数第二行,去重)=====') seen = [] for i, page in enumerate(doc): t = page.get_text() lines = [l.strip() for l in t.split('\n') if l.strip()] if len(lines) >= 2: cand = lines[-2] cand = re.sub(r'\s*\d+/169\s*$', '', cand).strip() if cand and (not seen or seen[-1][1] != cand) and not any(cand == s[1] for s in seen): seen.append((i + 1, cand)) for pno, foot in seen: print(f' p{pno}: {foot}') for p in [7, 11, 133, 134]: print(f'\n===== PAGE {p} 原文 =====') print(doc[p - 1].get_text()[:1200])