コード例 #1
0
ファイル: paper_bot.py プロジェクト: adityachandak287/ht-bot
def compress_file(file_name):
    try:
        compressed_file_name = "{}_compressed.pdf".format(file_name[:-4])
        compress(file_name, compressed_file_name, power=4)
        return compressed_file_name
    except:
        return file_name
コード例 #2
0
ファイル: main.py プロジェクト: real4suraj2/PDFCompressor
def upload_file():
    if request.method == 'POST':
        f = request.files['file']
        print('file', f)
        quality = request.form['quality']
        f.save(os.path.join(os.getcwd(), 'file.pdf'))
        compress('file.pdf', 'compressed.pdf', int(quality))
        return send_file('compressed.pdf', attachment_filename=f.filename)
コード例 #3
0
def creatUser(userDetails):
    response = {}
    home = os.environ['USERPROFILE']
    checkDir(E9PASS_BACKUP)
    certificateFilesPath = os.path.join(home, E9PASS_USER)
    pdfFilesPath = os.path.join(home, E9PASS_PDF)
    backUpDir = os.path.join(home, E9PASS_BACKUP)
    try:
        arcNumber = userDetails["arcNumber"]
        certificateName = userDetails["certificateName"]
        table = str.maketrans('', '', string.punctuation)
        folderName = arcNumber.translate(table)
        path = pathlib.Path(
            os.path.join(backUpDir, folderName + '\\NPKI\\KICA\\USER\\' +
                         certificateName))
        path.mkdir(parents=True, exist_ok=True)
        destination = os.path.join(
            backUpDir, folderName + '\\NPKI\\KICA\\USER\\' + certificateName)
        source = os.path.join(certificateFilesPath, certificateName)
        copyAndOverwrite(source, destination)
        response["certStatus"] = True
        response["certMsg"] = 'Success'
        try:
            pdfName = userDetails["pdfName"]
            source = os.path.join(pdfFilesPath, pdfName)
            destination = os.path.join(backUpDir,
                                       os.path.join(folderName, pdfName))
            result = None
            result = compress(source, destination, power=2)
            while result is None:
                pass
            response["pdfStatus"] = result
            response["pdfMsg"] = 'PDF Compress Status'
        except:
            response["pdfStatus"] = False
            response["pdfMsg"] = 'Unable to copy Pdf!'
        try:
            os.chdir(backUpDir)
            table = str.maketrans('', '', string.punctuation)
            fileName = arcNumber.translate(table)
            result = shutil.make_archive(fileName, 'zip', base_dir=folderName)
            if bool(result):
                shutil.rmtree(folderName)
            response["zipStatus"] = True
            response["zipMsg"] = 'Success'
            return response
        except:
            response["zipStatus"] = False
            response["zipMsg"] = 'Unable to Create ZIP Archive'
            return response
    except OSError as err:
        print(err)
        response["certStatus"] = False
        response["certMsg"] = 'Unable to copy Certificate!'
        return response
コード例 #4
0
ファイル: get_paper.py プロジェクト: adityachandak287/ht-bot
def compress_file(file_name):
    compressed_file_name = "{}_compressed.pdf".format(file_name)
    compress(file_name, compressed_file_name, power=4)
    return compressed_file_name
コード例 #5
0
from pdf_compressor import compress
print("Hello from inside the container!")

compress("Hindustan Times 04072020.pdf", "compressed.pdf", power=4)