29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
@app.route('/stampa_pdf', methods=['POST'])
|
|
def stampa_pdf():
|
|
try:
|
|
v = request.form.get('v', '0')
|
|
ps = request.form.get('ps', '0')
|
|
ts = request.form.get('ts', '0')
|
|
|
|
# Testo formattato in PostScript per evitare PDF vuoti
|
|
ps_content = f"""%!PS
|
|
/Helvetica findfont 14 scalefont setfont
|
|
100 750 moveto (REPORT CALCOLO CEMENTO) show
|
|
100 720 moveto (Volume: {v} m3) show
|
|
100 700 moveto (Peso: {ps} kg) show
|
|
100 680 moveto (Totale sacchetti: {ts}) show
|
|
showpage"""
|
|
|
|
# Comando per iniettare i dati nel container
|
|
comando = ["docker", "exec", "-i", "cups-pdf-server", "lp", "-d", "Virtual_PDF"]
|
|
|
|
# Esecuzione del comando passandogli il testo PostScript
|
|
processo = subprocess.run(comando, input=ps_content.encode('utf-8'), capture_output=True)
|
|
|
|
if processo.returncode == 0:
|
|
return "OK - PDF generato correttamente!"
|
|
else:
|
|
return f"Errore container: {processo.stderr.decode()}"
|
|
|
|
except Exception as e:
|
|
return f"Errore script: {str(e)}" |