import fitz  # PyMuPDF

def extract_answers_from_pdf(pdf_file):
    # 打开PDF文件
    doc = fitz.open(pdf_file)
    answers = []

    # 遍历每一页
    for page in doc:
        # 提取当前页的文本
        text = page.get_text() 
        # 分割文本为行
        lines = text.split('\n')
        for line in lines:
            if line.strip():  # 排除空白行
                # 分割等号，提取答案
                parts = line.split('=')
                if len(parts) > 1:
                    answer = parts[-1].strip()  # 取等号后的部分为答案
                    answers.append(answer)
    
    return answers

# 假设你的文件名是'math_problems.pdf'
pdf_file = '/Users/lxc/Desktop/calculus.pdf'
answers = extract_answers_from_pdf(pdf_file)
for i, answer in enumerate(answers, 1):
    print(f"题目{i}的答案是: {answer}")
