28 lines
949 B
Python
28 lines
949 B
Python
import pdfplumber
|
|
import os
|
|
|
|
# 使用当前脚本所在目录
|
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
|
pdf_path = os.path.join(script_dir, "2025 APMCM Problem B.pdf")
|
|
|
|
print(f"Looking for PDF at: {pdf_path}")
|
|
print(f"File exists: {os.path.exists(pdf_path)}")
|
|
|
|
if os.path.exists(pdf_path):
|
|
with pdfplumber.open(pdf_path) as pdf:
|
|
full_text = ""
|
|
for i, page in enumerate(pdf.pages):
|
|
text = page.extract_text()
|
|
if text:
|
|
full_text += f"\n=== Page {i+1} ===\n{text}\n"
|
|
print(full_text)
|
|
# 保存到文本文件
|
|
output_path = os.path.join(script_dir, "problem_text.txt")
|
|
with open(output_path, "w", encoding="utf-8") as f:
|
|
f.write(full_text)
|
|
print(f"\n文本已保存到: {output_path}")
|
|
else:
|
|
print(f"文件不存在: {pdf_path}")
|
|
print(f"当前工作目录: {os.getcwd()}")
|
|
print(f"目录内容: {os.listdir('.')}")
|