from flask import Flask, request
from PyPDF2 import PdfReader
from io import BytesIO

app = Flask(__name__)

@app.route('/pdfconv', methods=['GET','POST'])
def convert_file():

    simplebytes = request.data
    file = BytesIO(simplebytes)

    # try to convert to text
    try:
        pdf_reader=PdfReader(file, strict=False)
        text=""
        for page in pdf_reader.pages:
            text+=page.extract_text()
 
        return text
            
    except Exception as e:
            print(e)
            return "Error reading the PDF file."
    
