very dodgy prototype
This commit is contained in:
parent
2c69fd5bbe
commit
b3a857b15b
@ -4,6 +4,8 @@ An app that uses the [`temp-index`](https://pypi.org/project/temp-index/) python
|
||||
|
||||
## deploy it
|
||||
|
||||
[Install `pdfcpu`](https://github.com/pdfcpu/pdfcpu/releases) to `/usr/bin/pdfcpu`.
|
||||
|
||||
```
|
||||
sudo apt-get install libtiff5-dev libjpeg-dev libopenjp2-7-dev zlib1g-dev \
|
||||
libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python3-tk \
|
||||
|
13
app.py
13
app.py
@ -1,6 +1,8 @@
|
||||
import os
|
||||
import random
|
||||
import shutil
|
||||
import string
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
import petname
|
||||
@ -56,6 +58,15 @@ class UploadForm(FlaskForm):
|
||||
petname = HiddenField("petname")
|
||||
|
||||
|
||||
def impose_cards(fpath):
|
||||
"""Impose the cards with pdfcpu."""
|
||||
if shutil.which("pdfcpu"):
|
||||
old_fpath = "{}.old.pdf".format(fpath)
|
||||
shutil.move(fpath, old_fpath)
|
||||
cmd = 'pdfcpu booklet -- "p:A4, border:on" {} 4 {}'.format(fpath, old_fpath)
|
||||
subprocess.run(cmd, shell=True)
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def home():
|
||||
upload_form = UploadForm()
|
||||
@ -120,6 +131,8 @@ def upload():
|
||||
side_b,
|
||||
)
|
||||
|
||||
impose_cards(pdf_path)
|
||||
|
||||
gen_msg = (
|
||||
"Currently working on {}, click 'generate' to re-generate the same PDF"
|
||||
).format(pdf_name)
|
||||
|
Loading…
Reference in New Issue
Block a user