The tool relates to the project "No Annotation* is a Alone"; a series of annotative interventions upon the rigidity of PDF, to challenge established protocols.
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.

60 lines
1.7 KiB

2 years ago
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
2 years ago
from hocrtransformpdf import *
from werkzeug.utils import secure_filename
from flask_basicauth import BasicAuth
import pdftotree
import urllib.request
2 years ago
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"
2 years ago
@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():
2 years ago
# 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")
1 year ago
# 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)
2 years ago
d = {"url":"pdf/result.pdf"}
return d
2 years ago
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
if __name__ == "__main__":
app.run()