Browse Source

download pdf from url

master
nglk 2 years ago
parent
commit
65b8ffbe32
  1. BIN
      .app.py.swp
  2. BIN
      __pycache__/app.cpython-37.pyc
  3. 28
      app.py
  4. 378
      downloaded.pdf
  5. 9
      templates/results.html

BIN
templates/.results.html.swp → .app.py.swp

Binary file not shown.

BIN
__pycache__/app.cpython-37.pyc

Binary file not shown.

28
app.py

@ -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)

378
downloaded.pdf

File diff suppressed because one or more lines are too long

9
templates/results.html

@ -3,20 +3,21 @@
{% block content %}
<!-- <iframe src="https://pad.vvvvvvaria.org/wordmord.test" height="800" width="800"></iframe> -->
<form method="post">
<table>
<tr>
<td colspan="3">
<form method="post">
<!-- <input type="text" id="my_field" value="" wrap="soft"> -->
<textarea name="file" id="my_field" wrap="soft" placeholder="Επικόλληση του συνδέσμου του PDF του Ποινικού Κώδικα που βρήκατε στο ηλεκτρονικό ταχυδρομείο σας ή στο ΔΙΑΒΑΣΕΜΕ.txt, εδώ.
<textarea name="file" id="my_field" wrap="soft" placeholder="Επικόλληση του συνδέσμου του PDF του Ποινικού Κώδικα που βρήκατε στο ηλεκτρονικό ταχυδρομείο σας ή στο ΔΙΑΒΑΣΕΜΕ.txt, εδώ.
"></textarea>
</form>
</td>
</tr>
<tr>
<td colspan="3">
<button id="button3" onclick="readme()">ΔΙΑΒΑΣΕΜΕ.txt</button>
<button id="button5" type="submit" onclick="decode()">ΠΡΟΒΟΛΗ ΠΟΙΝΙΚΟΥ ΚΩΔΙΚΑ <img src="{{url_for('static', filename='images/closed.gif')}}"></button>
<button id="button5" onclick="decode()">ΠΡΟΒΟΛΗ ΠΟΙΝΙΚΟΥ ΚΩΔΙΚΑ <img src="{{url_for('static', filename='images/closed.gif')}}"></button>
<button id="button2" onclick="copy()"> ΑΝΤΙΓΡΑΦΗ ΚΩΔΙΚΑ</button>
<button id="button1" onclick="transform()">ΜΕΤΑΛΛΑΓΜΕΝΟΣ ΚΩΔΙΚΑΣ</button>
<button id="button4" onclick="window.open('{{url_for('static', filename='pdf/ΣΧΕΔΙΟ_ΜΕΤΑΛΛΑΓΜΕΝΟΥ_ΠΟΙΝΙΚΟΥ_ΚΩΔΙΚΑ_01.pdf')}}');">ΚΑΤΕΒΑΣΕ ΜΕΤΑΛΛΑΓΜΕΝΟ ΚΩΔΙΚΑ <img src="{{url_for('static', filename='images/open.gif')}}"> </button>
@ -48,7 +49,7 @@
</table>
</form>
<script>

Loading…
Cancel
Save