Compress pdf files before sending to end-user

This commit is contained in:
Sage Vaillancourt 2021-07-31 17:38:32 -04:00
parent fc037bd105
commit e37cc3db9b
2 changed files with 14 additions and 1 deletions

5
init
View File

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

View File

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