"""Page count, text layer coverage and outline of each Level-4 PDF."""
import sys, fitz, os
ROOT = r"D:/OneDrive - DolfTech/SABIS-EBooks/EBooks/French"
for d in sorted(os.listdir(ROOT)):
    f = os.path.join(ROOT, d, d + ".pdf")
    if not os.path.exists(f):
        continue
    doc = fitz.open(f)
    chars = [len(doc[i].get_text("text").strip()) for i in range(doc.page_count)]
    with_text = sum(1 for c in chars if c > 40)
    imgs = sum(len(doc[i].get_images()) for i in range(min(10, doc.page_count)))
    print(f"== {d}: {doc.page_count} pages, {with_text} with text, avg {sum(chars)//max(1,doc.page_count)} chars/page, images in first 10 pages: {imgs}, {os.path.getsize(f)//1048576} MB")
    toc = doc.get_toc()
    print("   toc entries:", len(toc), [t[1] for t in toc[:12]])
    links = sum(1 for i in range(doc.page_count) for l in doc[i].get_links())
    annots = sum(1 for i in range(doc.page_count) for a in (doc[i].annots() or []))
    print("   links:", links, "annotations:", annots)
