import os
import jieba
import fitz

# 如需要词性，把上一行改成：
# import jieba.posseg as jieba

# 提取 PDF 文本
def extract_text_from_pdf(pdf_path):
    doc = fitz.open(pdf_path)
    text = ""
    for page_num in range(len(doc)):
        page = doc.load_page(page_num)
        text += page.get_text()
    return text

# 主程序
if __name__ == "__main__":
    pdf_dir = "pdf"
    for filename in os.listdir(pdf_dir):
        pdf_path = os.path.join(pdf_dir, filename)
        text = extract_text_from_pdf(pdf_path)

        # jieba 分词
        tokens = jieba.lcut(text)          # 列表形式
        # 如需词性：tokens = [(w.word, w.flag) for w in jieba.lcut(text)]
        print(tokens)