add title
This commit is contained in:
parent
3f22a2ecd7
commit
5827d313ff
76
app.py.copy
76
app.py.copy
@ -10,6 +10,7 @@ from hocrtransformpdf import *
|
|||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
from flask_basicauth import BasicAuth
|
from flask_basicauth import BasicAuth
|
||||||
import pdftotree
|
import pdftotree
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
UPLOAD_FOLDER = 'static/uploads'
|
UPLOAD_FOLDER = 'static/uploads'
|
||||||
ALLOWED_EXTENSIONS = {'pdf'}
|
ALLOWED_EXTENSIONS = {'pdf'}
|
||||||
@ -26,66 +27,27 @@ app.config['UPLOAD_FOLDER'] = "static/pdf"
|
|||||||
|
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
@basic_auth.required
|
@basic_auth.required
|
||||||
def run_script():
|
def index():
|
||||||
# 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())
|
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):
|
def allowed_file(filename):
|
||||||
return '.' in filename and \
|
return '.' in filename and \
|
||||||
|
@ -4,6 +4,11 @@
|
|||||||
|
|
||||||
<!-- <iframe src="https://pad.vvvvvvaria.org/wordmord.test" height="800" width="800"></iframe> -->
|
<!-- <iframe src="https://pad.vvvvvvaria.org/wordmord.test" height="800" width="800"></iframe> -->
|
||||||
<table>
|
<table>
|
||||||
|
|
||||||
|
<td colspan="3" style="text-align: center;">
|
||||||
|
<h1>καμία* επισημείωση δεν είναι μόνη</h1>
|
||||||
|
</td>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="3">
|
<td colspan="3">
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
@ -24,7 +29,6 @@
|
|||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<div id="initialpdf">
|
<div id="initialpdf">
|
||||||
|
Loading…
Reference in New Issue
Block a user