cloudairambo / utils /ghostscript_utils.py
rihancloud's picture
Deploy clean FastAPI backend without node_modules
99fdb5f
Raw History Blame Contribute Delete
567 Bytes
import subprocess
import os
import uuid
from core.config import settings
def compress_pdf(input_path: str):
output_filename = f"{uuid.uuid4()}.pdf"
output_path = os.path.join(settings.OUTPUT_DIR, output_filename)
cmd = [
"gs",
"-sDEVICE=pdfwrite",
"-dCompatibilityLevel=1.5",
"-dPDFSETTINGS=/ebook",
"-dNOPAUSE",
"-dQUIET",
"-dBATCH",
f"-sOutputFile={output_path}",
input_path,
]
subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return output_path