import os
from pypdf import PdfReader
pdf_file_path = ""
file_name = os.path.splitext(pdf_file_path)[0]
reader = PdfReader(pdf_file_path)
text = ""
for page in reader.pages:
text += page.extract_text() + "\n"
with open(f"{file_name}.txt", "w") as f:
f.write(text)
print(text)
Reference:
extrair texto de todo o PDF e salvar em um arquivo de texto