Skip to content

Instantly share code, notes, and snippets.

@hendrixcosta
Forked from drmcarvalho/pyremovepasspdf.py
Created August 29, 2022 14:52
Show Gist options
  • Select an option

  • Save hendrixcosta/4899a7048a068a8c890f529eb1f03e11 to your computer and use it in GitHub Desktop.

Select an option

Save hendrixcosta/4899a7048a068a8c890f529eb1f03e11 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