import os
import pypdf

def check_annotations(pdf_path):
    try:
        reader = pypdf.PdfReader(pdf_path)
        total_annotations = 0
        print(f"Checking: {os.path.basename(pdf_path)}")
        
        for page_num, page in enumerate(reader.pages):
            if "/Annots" in page:
                annots = page["/Annots"]
                count = len(annots)
                total_annotations += count
                print(f"  Page {page_num + 1}: Found {count} annotations")
                # Optional: Print types of annotations
                for annot in annots:
                    obj = annot.get_object()
                    print(f"    Type: {obj.get('/Subtype')}, Contents: {obj.get('/Contents')}")
            else:
                pass
                # print(f"  Page {page_num + 1}: No annotations")
                
        print(f"  Total Annotations: {total_annotations}")
        print("-" * 30)
        return total_annotations
    except Exception as e:
        print(f"Error checking {pdf_path}: {e}")
        return 0

if __name__ == "__main__":
    files = [
        r"C:\Users\Administrator\.gemini\antigravity\scratch\bluebeam-comment-conv\05 05 23.13 10 markup.pdf",
        r"C:\Users\Administrator\.gemini\antigravity\scratch\bluebeam-comment-conv\05 12 00 markup.pdf",
        r"C:\Users\Administrator\.gemini\antigravity\scratch\bluebeam-comment-conv\05 21 00 markup.pdf",
        r"C:\Users\Administrator\.gemini\antigravity\scratch\bluebeam-comment-conv\05 30 00 markup.pdf",
        r"C:\Users\Administrator\.gemini\antigravity\scratch\bluebeam-comment-conv\05 40 00 markup.pdf",
        r"C:\Users\Administrator\.gemini\antigravity\scratch\bluebeam-comment-conv\05 50 14 markup.pdf",
        r"C:\Users\Administrator\.gemini\antigravity\scratch\bluebeam-comment-conv\06 17 19 markup.pdf",
        r"C:\Users\Administrator\.gemini\antigravity\scratch\bluebeam-comment-conv\06 17 19 markup_saveas2.pdf"
    ]
    
    for f in files:
        if os.path.exists(f):
            check_annotations(f)
        else:
            print(f"File not found: {f}")
