diff --git a/__pycache__/app.cpython-37.pyc b/__pycache__/app.cpython-37.pyc index 901cd81..d2a2400 100644 Binary files a/__pycache__/app.cpython-37.pyc and b/__pycache__/app.cpython-37.pyc differ diff --git a/app.py b/app.py index 489cd39..8bd0500 100644 --- a/app.py +++ b/app.py @@ -10,6 +10,7 @@ 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'} @@ -26,65 +27,25 @@ app.config['UPLOAD_FOLDER'] = "static/pdf" @app.route('/', methods=['GET', 'POST']) @basic_auth.required -def run_script(): +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': - # download PDF from url - file = request.form['file'] - if file: - response = urllib.request.urlopen(file) - file = open("static/pdf/downloaded.pdf", 'wb') - file.write(response.read()) - file.close() - #uploadfilepath=os.path.join(app.config['UPLOAD_FOLDER'], file) - #file.save(uploadfilepath) - #return redirect(url_for('uploaded_file',file=file)) - # url = request.form['url'] - #if not url: - # flash('Url is required!') - # else: - # messages.append({'url': url}) - # return redirect(url_for('index')) - - # check if the post request has the file part - #if 'file' not in request.files: - # flash('No file part') - # return redirect(request.url) - #file = request.files['file'] - # if user does not select file, browser also - # submit an empty part without filename - #if file.filename == '': - # flash('No selected file') - # return redirect(request.url) - #if file and allowed_file(file.filename): - # filename = secure_filename(file.filename) - # uploadfilepath=os.path.join(app.config['UPLOAD_FOLDER'], filename) - # file.save(uploadfilepath) - # return redirect(url_for('uploaded_file', - # filename=filename)) - - - hocr_result = pdftotree.parse("static/pdf/downloaded.pdf") - hocr = HocrTransform(hocr_filename=hocr_result, dpi=300) - hocr.to_pdf( - out_filename='static/pdf/output-2.pdf', - image_filename='static/images/blank.png', - show_bounding_boxes=False, - interword_spaces=False - ) - - #hocrfile='static/hocr/gynaikoktonia.hocr' - #hocr = HocrTransform(hocr_filename=hocrfile, dpi=300) - #hocr = HocrTransform(hocr_filename=hocr_result, dpi=300) - #hocr.to_pdf( - # out_filename='static/pdf/output.pdf', - # image_filename='static/images/blank.png', - # show_bounding_boxes=False, - # interword_spaces=False, - #) -# result = subprocess.check_output("python3 hocrtransformpdf.py -i images/blank.png hocr/gynaikoktonia.hocr pdf/gynaikoktonia.pdf", shell=True) - return render_template('results.html', **locals()) + content = request.get_json(silent=True) + print(content["hocr"]) + urllib.request.urlretrieve(content["pdf"], "static/pdf/input.pdf") + + 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): diff --git a/app.py.copy b/app.py.copy index 2eecfbb..489cd39 100644 --- a/app.py.copy +++ b/app.py.copy @@ -10,7 +10,6 @@ from hocrtransformpdf import * from werkzeug.utils import secure_filename from flask_basicauth import BasicAuth import pdftotree -from parsepdf import hocr_result UPLOAD_FOLDER = 'static/uploads' ALLOWED_EXTENSIONS = {'pdf'} @@ -28,6 +27,7 @@ app.config['UPLOAD_FOLDER'] = "static/pdf" @app.route('/', methods=['GET', 'POST']) @basic_auth.required def run_script(): + # 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': # download PDF from url file = request.form['file'] @@ -36,22 +36,6 @@ def run_script(): file = open("static/pdf/downloaded.pdf", 'wb') file.write(response.read()) file.close() - #hocr = pdftotree.parse("static/pdf/downloaded.pdf") - #hocrfile=open("static/hocr/downloaded.hocr", 'wb') - #hocrfile.write(hocr.read()) - #hocrfile.close - #output = execute('python parsepdf.py') - #hocr_result = pdftotree.parse("static/pdf/downloaded.pdf") - #hocr_result=hocr_result() - -#hocr = HocrTransform(hocr_result, 300) - #hocr.to_pdf( - # out_filename='static/pdf/output-2.pdf', - #image_filename='static/images/blank.png', - #show_bounding_boxes=False, - #interword_spaces=False, - #) - #uploadfilepath=os.path.join(app.config['UPLOAD_FOLDER'], file) #file.save(uploadfilepath) #return redirect(url_for('uploaded_file',file=file)) @@ -80,14 +64,14 @@ def run_script(): # filename=filename)) - # hocr_result = pdftotree.parse("static/pdf/downloaded.pdf") - #hocr = HocrTransform(hocr_filename=hocr_result, dpi=300) - #hocr.to_pdf( - # out_filename='static/pdf/output-2.pdf', - # image_filename='static/images/blank.png', - # show_bounding_boxes=False, - # interword_spaces=False - #) + hocr_result = pdftotree.parse("static/pdf/downloaded.pdf") + hocr = HocrTransform(hocr_filename=hocr_result, dpi=300) + hocr.to_pdf( + out_filename='static/pdf/output-2.pdf', + image_filename='static/images/blank.png', + show_bounding_boxes=False, + interword_spaces=False + ) #hocrfile='static/hocr/gynaikoktonia.hocr' #hocr = HocrTransform(hocr_filename=hocrfile, dpi=300) @@ -98,8 +82,9 @@ def run_script(): # show_bounding_boxes=False, # interword_spaces=False, #) - #subprocess.check_output("python hocrtransformpdf.py -i static/images/blank.png static/hocr/downloaded.hocr static/pdf/output-2.pdf", shell=True) - return render_template('results.html',**locals()) +# result = subprocess.check_output("python3 hocrtransformpdf.py -i images/blank.png hocr/gynaikoktonia.hocr pdf/gynaikoktonia.pdf", shell=True) + return render_template('results.html', **locals()) + def allowed_file(filename): diff --git a/static/hocr/gynaikoktonia.hocr b/static/hocr/gynaikoktonia.hocr index 2f17b51..3d38000 100644 --- a/static/hocr/gynaikoktonia.hocr +++ b/static/hocr/gynaikoktonia.hocr @@ -1,142 +1,639 @@ - - - -
-- ΕΓΚΛΗΜΑΤΑ ΚΑΤΑ ΤΗΣ ΖΩΗΣ ΚΑΙ ΠΡΟΣΒΟΛΕΣ ΤΩΝ ΘΥΛΗΚΟΤΗΤ* - - Ι. Εγκλήματα βλάβης της ζωής της ●●●●●●●● - -
-- Άρθρο 299 - - Γυναικοκτονία με δόλο - -
-- 1. Όποιος σκότωσε άλλη τιμωρείται με κάθειρξη ισόβια ή πρόσκαιρη τουλάχιστον δέκα ετών. - - 2. Αν η πράξη αποφασίστηκε και εκτελέστηκε σε βρασμό ψυχικής ορμής, επιβάλλεται κάθειρξη. - -
-- ●●●●● ●●● - - ●●●●●●●●●●●●● ●●●● ●●●●●●●● - -
-- ●●●●●● ●●●●●●●●● ●●● ●●●●●●●● ●●●●●●●●●●●●● ●●●●●● ●●● ●●●●●●●● ●●● ●●●●●●● ●●●●●●●● - - ●●● ●●●●●●● ●●● ●●● ●●●●● ●●● ●●●●● ●●● ●●●●●● ●●● ●●●●●● ●●●●●●●● ●●●●●●●●●● ●● ●●●●●●●●● - -
-- Άρθρο 301 - - Συμμετοχή σε αυτοκτονία - -
-- Όποιος κατέπεισε άλλην να αυτοκτονήσει, αν τελέστηκε η αυτοκτονία ή έγινε απόπειρά της, - - καθώς και όποιος έδωσε βοήθεια κατά την τέλεσή της, η οποία διαφορετικά δεν θα ήταν εφικτή, - - τιμωρείται με φυλάκιση. - -
-- Άρθρο 302 - - Γυναικοκτονία από θεσμική αμέλεια - -
-- Όποιος από αμέλεια σκότωσε άλλην, τιμωρείται με φυλάκιση τουλάχιστον τριών μηνών. - -
-- Άρθρο 303 - - Παιδοκτονία - -
-- Πατέρας που με πρόθεση σκότωσε την κόρη του κατά ή μετά τον τοκετό, αλλά ενώ εξακολουθούσε - - ακόμη η διατάραξη του οργανισμού της από αυτόν, τιμωρείται με κάθειρξη έως δέκα έτη. - -
-- ●●● ●●●●●●●●● ●●● ●●●●●●● - -
-- ●●●●● ●●● - - ●●●●●●● ●●● ●●●●●● - -
-- ●● ●●●●●● ●●●●● ●● ●●●●●●●●● ●●● ●●●●●● ●●●●●●●●● ●●● ●●●●● ●●● ●●●●●●●●●● ●● ●●●●●●●● ●●● - - ●●●● ●●●● - -
- -- ●● ●●●●●● ●● ●● ●●●●●●●●● ●●● ●●●●●● ● ●●● ●●●●●●●● ●●● ●●●●● ●● ●●●●●● ●●●●●●● ● - - ●●●●●●●●● ●●● ●● ●●●● ●●●●● ●●●●●●● ●● ●●●●●●●●●●● ●●●●●●●●● ●●● ●●●● ●●●●●●● ●●●● ●●●●●●●●●● ●● - - ●●●●●●●● ●●● ●●●● ●●● ● ●●●●●●●●● ●●●●● ●●● ●● ●●●●●●● ●●●● ●●●●●●●●● ●● ●●●●●●●● - - ●●●●●●●●●●● ●●● ●●●● ●●● ●●●●●●●●● ●●●●●● ●● ●●● ●●●● ●●●●●● ●●●●●●●● ●●●● ●● ●●●●● ●●● - -
-- 78 - -
-