File size: 613 Bytes
851f3c6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import os
from pypdf import PdfReader
def extract_text_from_pdf(pdf_path: str) -> str:
reader = PdfReader(pdf_path)
chunks = []
for page in reader.pages:
chunks.append(page.extract_text() or "")
return "\n".join(chunks).strip()
def save_uploaded_pdf(src_path: str, dest_dir: str) -> str:
os.makedirs(dest_dir, exist_ok=True)
base = os.path.basename(src_path)
dest_path = os.path.join(dest_dir, base)
# перезапись ок для пилота
with open(src_path, "rb") as fsrc, open(dest_path, "wb") as fdst:
fdst.write(fsrc.read())
return dest_path
|