This web app uses Optical Character Recognition (OCR) to extract text from PDF files, such as those found on Internet Archive. The app is built using Flask, a Python web framework, and utilizes the pdf2image and pytesseract libraries for PDF processing and OCR.
from flask import Flask, request, jsonify
from pdf2image import convert_from_bytes
import pytesseract
from PIL import Image
import io
app = Flask(__name__)
# Tesseract OCR engine configuration
pytesseract.pytesseract.tesseract_cmd = '/usr/bin/tesseract' # Update this path according to your Tesseract installation
@app.route('/extract_text', methods=['POST'])
def extract_text():
# Get PDF file from request
pdf_file = request.files['pdf_file']
# Convert PDF to images
images = convert_from_bytes(pdf_file.read())
# Extract text from images using OCR
text = ''
for image in images:
text += pytesseract.image_to_string(image)
return jsonify({'text': text})
if __name__ == '__main__':
app.run(debug=True)
from app import app
@app.route('/')
def index():
return render_template('index.html')
Usage
Run the Flask app: python app.py
Open a web browser and navigate to http://localhost:5000
Select a PDF file using the file input field
Click the "Extract Text" button to extract the text from the PDF file
The extracted text will be displayed on the page
Example Use Case
Upload a PDF file from Internet Archive to the web app
Extract the text from the PDF file using OCR
Display the extracted text on the web page for further processing or analysis
Notes
This implementation assumes that the PDF files are not encrypted and contain text that can be extracted using OCR.
The accuracy of the OCR output depends on the quality of the PDF file and the Tesseract OCR engine configuration.
This is a basic implementation and may require further optimization and customization for production use.
User
Refactor as a single file minimalistic web app using only HTML,CSS, and JavaScript
Assistant
PDF Text Extraction Web App (Single File)
Below is a minimalistic single-file web app that extracts text from PDF files using the Tesseract.js library, which is a JavaScript wrapper for Tesseract OCR.