File size: 437 Bytes
325b94c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import requests
import io
from PyPDF2 import PdfReader

def extract_pdf_content(url: str) -> str:
    try:
        pdf_bytes = requests.get(url, timeout=10).content
        pdf_file = io.BytesIO(pdf_bytes)
        reader = PdfReader(pdf_file)

        text = ""
        for page in reader.pages:
            text += page.extract_text() or ""

        return text.strip()

    except Exception as e:
        return f"PDF_ERROR: {str(e)}"