Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

working on python 3.8.5 #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions python/pdf_password_remover.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@
import logging
import coloredlogs

#CHANGE PASSWORD HERE
pdf_password = "0"
# CHANGE PASSWORD HERE
pdf_password = "changeme"

#Logs to scriptName.log
# Logs to scriptName.log
scriptName = os.path.basename(__file__)
logging.basicConfig(level = logging.DEBUG,
filename = scriptName + ".log",
filemode = "a",
encoding = 'utf-8',
format = '[%(asctime)s] [%(levelname)s] %(message)s')
logging.basicConfig(level=logging.DEBUG,
filename=scriptName + ".log",
filemode="a",
format='[%(asctime)s] [%(levelname)s] %(message)s')

#Logs into console
# Logs into console
mylogs = logging.getLogger(__name__)
stream = logging.StreamHandler()
mylogs.addHandler(stream)
coloredlogs.install(level=logging.DEBUG,
coloredlogs.install(level=logging.DEBUG,
logger=mylogs,
fmt='[%(asctime)s] [%(levelname)s] %(message)s')

Expand All @@ -29,19 +28,20 @@
filepath = subdir + os.sep + file
if filepath.endswith(".pdf"):
nb += 1
mylogs.info(str(nb) + ") File processing : " + file + " (" + filepath +")")
#Check if th PDF is password locked
try:
mylogs.info(str(nb) + ") File processing : " + file + " (" + filepath + ")")
# Check if the PDF is password locked
try:
pdf = pikepdf.open(filepath)
mylogs.info(file + " isn't lock with a password")
except pikepdf._qpdf.PasswordError:
#If locked, try to unlock with password line 7
mylogs.info(file + " isn't locked with a password")
except pikepdf.PasswordError:
# If locked, try to unlock with password line 7
try:
pdf = pikepdf.open(filepath, password=pdf_password, allow_overwriting_input=True)
pdf.save(filepath)
mylogs.info ("Successfully remove password on " + file)
except pikepdf._qpdf.PasswordError:
mylogs.error ("Bad password for " + file)
except: #default
mylogs.error ("Failed to remove password on " + file)
os.system("pause")
mylogs.info("Successfully remove password on " + file)
except pikepdf.PasswordError:
mylogs.error("Bad password for " + file)
except: # default
mylogs.error("Failed to remove password on " + file)

input("Press Enter to continue...")