import pdfplumber
import os

base = r"C:\Users\HP\palmgrove\NEFDB\docs\waste_water\supplement"
files = [
    "kano_msw_composition_afuno_rabiu_2017.pdf",
    "abuja_msw_characterization_abur_2014.pdf",
    "rivers_state_msw_composition_port_harcourt.pdf",
    "nigeria_multi_city_swm_thesis_scholaris.pdf",
    "epe_olusosun_air_quality_2024.pdf",
    "kaduna_textile_effluents_yusuff.pdf",
    "uyo_brewery_effluent_2020.pdf",
]

for fn in files:
    path = os.path.join(base, fn)
    if not os.path.exists(path):
        print(f"missing {fn}")
        continue
    out = path.replace(".pdf", ".md")
    try:
        with pdfplumber.open(path) as pdf:
            text = "\n\n".join(page.extract_text() or "" for page in pdf.pages)
        with open(out, "w", encoding="utf-8") as f:
            f.write(f"# Extracted text from {fn}\n\n{text}")
        print(f"Extracted {fn}: {len(text)} chars")
    except Exception as e:
        print(f"Error {fn}: {e}")
