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

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
1 year ago
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
1 year ago
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':
1 year ago
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)
1 year ago
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()