code: def compress_pdf(filepath, output_path, ghostscript_binary):
      
      if not filepath.endswith(PDF_EXTENSION):
          raise ValueError("Filename must end with .pdf!\n%s does not." % filepath)
      try:
          file_size = os.stat(filepath).st_size
          if file_size < FILE_SIZE_LOWER_LIMIT:
              LOGGER.info(NOT_COMPRESSING.format(filepath, file_size, FILE_SIZE_LOWER_LIMIT))
              process = subprocess.Popen(['cp', filepath, output_path])
          else:
              LOGGER.info(COMPRESSING.format(filepath))
              process = subprocess.Popen(
                  [ghostscript_binary, "-sDEVICE=pdfwrite",
                   "-dCompatabilityLevel=1.4", "-dPDFSETTINGS=/ebook",
                   "-dNOPAUSE", "-dQUIET", "-dBATCH",
                   "-sOutputFile=%s" % output_path, filepath]
                  )
      except FileNotFoundError:
          msg = GS_NOT_INSTALLED.format(ghostscript_binary)
          raise FileNotFoundError(msg)
      process.communicate()
      LOGGER.info(FILE_DONE.format(output_path))
docs: Compress a single PDF file.
  
      Args:
          filepath (str): Path to the PDF file.
          output_path (str): Output path.
          ghostscript_binary (str): Name/alias of the Ghostscript binary.
  
      Raises:
          ValueError
          FileNotFoundError