diff_format_zxh2.py 778 B

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