01 Python pikepdf 解锁带有密码的PDF文件

 文件名:unlockPDF.py

#!/Users/don/anaconda3/bin/python
# 使用方法:python unlockPDF.py 文件绝对地址/文件名.pdf
import os
import sys
import pikepdf

def unlock_file(file):
	pdf = pikepdf.open(file, allow_overwriting_input=True)
	pdf.save(file)


def unlock_directory(folder = './'):
	os.chdir(folder)
	filelist = os.listdir()
	for file in filelist:
		if os.path.splitext(file)[1] == '.pdf':
			unlock_file(file)

if __name__ == '__main__':

	if len(sys.argv) == 1:
		unlock_directory()
	else:
		target = sys.argv[1]
		if (os.path.isdir(target)):
			unlock_directory(target)
		else:
			unlock_file(target)

	print('done')

你可能感兴趣的:(工具集,python,开发语言)