-
-
Save hendrixcosta/4899a7048a068a8c890f529eb1f03e11 to your computer and use it in GitHub Desktop.
Script para remover senha de arquivo PDF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| import time | |
| import Tkinter as tk | |
| import tkFileDialog | |
| import os | |
| import pipes | |
| def unix(): | |
| return os.name == 'posix' | |
| def abrirArquivo(): | |
| root = tk.Tk() | |
| root.withdraw() | |
| path = tkFileDialog.askopenfilename(defaultextension = '.pdf').encode('utf-8') | |
| return pipes.quote(path) if path else '' | |
| if unix(): | |
| novoPdf = "" | |
| print("===== Remover senha do PDF =====\n\n\n") | |
| senhaPdf = raw_input("Digite a senha do arquivo PDF: ") | |
| print("Selecione um arquivo PDF com senha.") | |
| arquivoPdfComSenha = abrirArquivo() | |
| if arquivoPdfComSenha: | |
| novoPdf = "novo-pdf-sem-senha-{data}".format(data = time.strftime("%d-%m-%Y")) | |
| comando = "qpdf --password={senha} --decrypt {pdfEntrada} {pdfSaida}".format(senha = senhaPdf, pdfEntrada = arquivoPdfComSenha, pdfSaida = novoPdf) | |
| os.system(comando) | |
| print("Novo pdf: {pdf}").format(pdf = novoPdf) | |
| else: | |
| print("\nArquivo não selecionado.") | |
| else: | |
| print("Oops...o script só funciona em sistemas operacionais Unix (linux).") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment