Skip to content

Instantly share code, notes, and snippets.

@drmcarvalho
Created April 2, 2017 16:46
Show Gist options
  • Save drmcarvalho/65792fd9c1a91c74e748e42b031cfe03 to your computer and use it in GitHub Desktop.
Save drmcarvalho/65792fd9c1a91c74e748e42b031cfe03 to your computer and use it in GitHub Desktop.
Script para remover senha de arquivo PDF
#!/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