|
|
@ -5,6 +5,7 @@ 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 |
|
|
@ -31,9 +32,13 @@ def run_script(): |
|
|
|
# download PDF from url |
|
|
|
file = request.form['file'] |
|
|
|
if file: |
|
|
|
uploadfilepath=os.path.join(app.config['UPLOAD_FOLDER'], file) |
|
|
|
file.save(uploadfilepath) |
|
|
|
return redirect(url_for('uploaded_file',file=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!') |
|
|
@ -59,15 +64,14 @@ def run_script(): |
|
|
|
# filename=filename)) |
|
|
|
|
|
|
|
|
|
|
|
hocr_result = pdftotree.parse(uploadfilepath) |
|
|
|
app.logger.info("test") |
|
|
|
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) |
|
|
|