import os import pypdf def extract_pdf_pages_to_file(pdf_path, start_page, end_page, output_txt): print(f"Extracting {os.path.basename(pdf_path)} from page {start_page} to {end_page}...") reader = pypdf.PdfReader(pdf_path) total_pages = len(reader.pages) with open(output_txt, "w", encoding="utf-8") as f: for p_idx in range(start_page - 1, min(end_page, total_pages)): f.write(f"\n--- PAGE {p_idx + 1} (Thesis Page {p_idx - 12}) ---\n") text = reader.pages[p_idx].extract_text() f.write(text) f.write("\n") print(f"Extraction complete. Output written to {output_txt}") if __name__ == "__main__": pdf_file = "PERANCANGAN SISTEM REKOMENDASI KAMERA PADA PERSEWAAN KAMERA DENGAN BERBASIS WEBSITE MENGUNAKAN ALGORITMA TOPSIS (Revisi 3).pdf" if os.path.exists(pdf_file): extract_pdf_pages_to_file(pdf_file, 108, 120, "extracted_pages.txt") else: print(f"File {pdf_file} not found.")