You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.7 KiB
59 lines
1.7 KiB
import os
|
|
import random
|
|
import shutil
|
|
import string
|
|
import subprocess
|
|
from pathlib import Path
|
|
from flask import Flask, flash, redirect, render_template, request, url_for
|
|
import urllib.request
|
|
from hocrtransformpdf import *
|
|
from werkzeug.utils import secure_filename
|
|
from flask_basicauth import BasicAuth
|
|
import pdftotree
|
|
import urllib.request
|
|
|
|
UPLOAD_FOLDER = 'static/uploads'
|
|
ALLOWED_EXTENSIONS = {'pdf'}
|
|
|
|
app = Flask(__name__)
|
|
|
|
app.config['BASIC_AUTH_USERNAME'] = 'wordmord'
|
|
app.config['BASIC_AUTH_PASSWORD'] = 'tentacles'
|
|
|
|
basic_auth = BasicAuth(app)
|
|
|
|
app.config['UPLOAD_FOLDER'] = "static/pdf"
|
|
|
|
|
|
@app.route('/', methods=['GET', 'POST'])
|
|
@basic_auth.required
|
|
def index():
|
|
return render_template('results.html', **locals())
|
|
|
|
|
|
@app.route('/transform', methods=['POST'])
|
|
@basic_auth.required
|
|
def transform():
|
|
# the code below was made in case I was using a button upload but now I use the field input so this has to be uploaded and then transformed
|
|
if request.method == 'POST':
|
|
content = request.get_json(silent=True)
|
|
print(content["hocr"])
|
|
urllib.request.urlretrieve(content["pdf"], "static/pdf/input.pdf")
|
|
|
|
# the outcome of this hocr doesnt write well on the pdf, its structure doesn't fit
|
|
# hocr = subprocess.call("pdftotree static/pdf/input.pdf -o static/hocr/gynaikoktonia.hocr", shell=True)
|
|
|
|
result = subprocess.call("python3 hocrtransformpdf.py -i static/images/blank.png static/hocr/gynaikoktonia.hocr static/pdf/result.pdf", shell=True)
|
|
|
|
d = {"url":"pdf/result.pdf"}
|
|
return d
|
|
|
|
|
|
def allowed_file(filename):
|
|
return '.' in filename and \
|
|
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run()
|
|
|
|
|