by Lazy Sloth
Scrape Data from PDF using Python & Flask
from flask import Flask, request, render_template, jsonify
import PyPDF2
import io
from gunicorn.app.base import BaseApplication
from logging_config import configure_logging
app = Flask(__name__)
@app.route("/")
def root_route():
return render_template('upload.html')
@app.route("/upload", methods=["POST"])
def upload_pdf():
if 'pdf_file' not in request.files:
return "No file part"
file = request.files['pdf_file']
if file.filename == '':
return "No selected file"
if file and allowed_file(file.filename):
pdfReader = PyPDF2.PdfReader(io.BytesIO(file.read()))
text = ""
for page in pdfReader.pages:
Scrape Data from PDF using Python & Flask
Created: | Last Updated:
Introduction to the PDF Data Extraction Template
Welcome to the Lazy template guide for extracting data from PDF files. This template is designed to help you build an application that allows users to upload PDF files and then displays the extracted text on a webpage. This is particularly useful for those looking to automate the process of data retrieval from PDF documents without delving into the complexities of programming or deployment.
Getting Started
To begin using this template, simply click on "Start with this Template" on the Lazy platform. This will pre-populate the code in the Lazy Builder interface, so you won't need to copy, paste, or delete any code manually.
Test: Deploying the App
Once you have initiated the template, press the "Test" button. This will begin the deployment of your application on the Lazy platform. The Lazy CLI will handle the deployment process, and you won't need to worry about installing libraries or setting up your environment.
Using the App
After the deployment is complete, you will receive a dedicated server link. This link will take you to the web interface where you can upload a PDF file. Here's how to use the interface:
- Visit the provided server link to access the upload page.
- Click on the "Choose File" button to select the PDF file you wish to extract data from.
- After selecting the file, click on the "Submit" button to upload the file and process it.
- The application will then display the extracted text on a new webpage.
Integrating the App
If you wish to integrate this PDF data extraction functionality into another service or frontend, you can use the server link provided by Lazy. For instance, you could embed the link in an iframe within your existing web application or use it as part of a larger workflow that requires PDF data extraction.
Here is a sample code snippet that you could use to integrate the upload form into another HTML page:
<iframe src="YOUR_LAZY_SERVER_LINK/upload.html" width="100%" height="500"></iframe>
Replace "YOUR_LAZY_SERVER_LINK" with the actual link provided by Lazy.
Remember, this template is designed to work seamlessly within the Lazy platform, so all the heavy lifting of deployment and environment configuration is taken care of for you. Enjoy building your PDF data extraction tool with ease!
Technologies
![Flask](https://cdn.iconscout.com/icon/free/png-256/free-flask-liquid-chemistry-science-project-research-46203.png?f=webp&w=128)
![Python](https://i.pinimg.com/originals/2f/9c/11/2f9c11f9e55efbf1791f12c06d60729b.jpg)