Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created May 26, 2022 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/59d63f5f0c0811edac899d20737447cb to your computer and use it in GitHub Desktop.
Save parzibyte/59d63f5f0c0811edac899d20737447cb to your computer and use it in GitHub Desktop.
import io
from flask import Flask, render_template, request, send_file
from firmador import firmar
app = Flask(__name__)
app.config['TEMPLATES_AUTO_RELOAD'] = True
@app.route('/')
def index():
return render_template("formulario.html")
@app.route('/procesar', methods=['POST'])
def procesar():
pdf = request.files.get("pdf")
firma = request.files.get("firma")
contraseña = request.form.get("palabra_secreta")
archivo_pdf_para_enviar_al_cliente = io.BytesIO()
try:
datau, datas = firmar(contraseña, firma, pdf)
archivo_pdf_para_enviar_al_cliente.write(datau)
archivo_pdf_para_enviar_al_cliente.write(datas)
archivo_pdf_para_enviar_al_cliente.seek(0)
return send_file(archivo_pdf_para_enviar_al_cliente, mimetype="application/pdf",
download_name="firmado" + ".pdf",
as_attachment=True)
except ValueError as e:
return "Error firmando: " + str(e) + " . Se recomienda revisar la contraseña y el certificado"
if __name__ == "__main__":
app.run(host='0.0.0.0', port=81)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment