import fitz
import os

pdf = r"D:\Wordpress Backup\1 wordpress Plugins\icomm.systems plugins\icomm-metrix\samples\lrz-monthly-report-sample.pdf"
out_dir = r"D:\Wordpress Backup\1 wordpress Plugins\icomm.systems plugins\icomm-metrix\samples\lrz-report-pages"
os.makedirs(out_dir, exist_ok=True)
doc = fitz.open(pdf)
print("pages", doc.page_count)
texts = []
for i, page in enumerate(doc):
    t = page.get_text("text")
    texts.append(f"===== PAGE {i+1} =====\n{t}")
    pix = page.get_pixmap(matrix=fitz.Matrix(1.5, 1.5), alpha=False)
    pix.save(os.path.join(out_dir, f"page-{i+1:02d}.png"))
txt_path = os.path.join(out_dir, "extracted.txt")
full = "\n\n".join(texts)
with open(txt_path, "w", encoding="utf-8") as f:
    f.write(full)
print("wrote", txt_path)
print(full[:8000])
