From e37cc3db9b172c8fbe48a907eea523ef7ca54e41 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Sat, 31 Jul 2021 17:38:32 -0400 Subject: [PATCH] Compress pdf files before sending to end-user --- init | 5 +++++ latty.py | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/init b/init index 203fda0..d782c0c 100755 --- a/init +++ b/init @@ -24,6 +24,11 @@ if ! whereis pdflatex | grep "/" &> /dev/null; then failed=true fi +if ! whereis gs | grep "/" &> /dev/null; then + echo "ghostscript" $NEEDS + failed=true +fi + if $failed; then fail fi diff --git a/latty.py b/latty.py index f4b5322..51c22d1 100644 --- a/latty.py +++ b/latty.py @@ -64,10 +64,18 @@ class CLData(): if result.returncode == 0: print(build_text + "[SUCCESS]") threading.Timer(60 * 5, cleanup, [output_dir + unique_id]).start() + compress_com = "gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dNOPAUSE -dQUIET -dBATCH -dPrinted=false -sOutputFile=outputs/" + unique_id + ".compressed.pdf outputs/" + unique_id + ".pdf" + print(compress_com) + + result = subprocess.run( + ['bash', '-c', compress_com], + stdout=subprocess.PIPE, + text=True + ) return (send_from_directory( output_dir, - unique_id + ".pdf", + unique_id + ".compressed.pdf", attachment_filename=self.username.replace(" ", "") + "_CoverLetter.pdf", as_attachment=True ), None)