import streamlit as st import PyPDF2 from io import BytesIO def search_pdf(pdf_file, search_term): with BytesIO(pdf_file.read()) as file: reader = PyPDF2.PdfReader(file) num_pages = len(reader.pages) search_results = [] for page_num in range(num_pages): page = reader.pages[page_num] text = page.extract_text() if search_term.lower() in text.lower(): search_results.append((page_num + 1, text)) return search_results def final_result(pdf_file, search_term): results = search_pdf(pdf_file, search_term) output_text = "" if results: for page_num, text in results: # output_text += f"Found \033[1m'{search_term}'\033[0m on page {page_num}:\n{text}\n\n" output_text += f"'{search_term}' on page {page_num}:\n-{text}\n\n" else: output_text = f"No results found for '{search_term}'." return output_text st.set_page_config(page_title="Search in PDF", layout="wide",initial_sidebar_state="expanded") st.markdown("