Last active
September 16, 2022 15:15
-
-
Save zhangchunlin/4622c0c405eace64f2d3256e18252952 to your computer and use it in GitHub Desktop.
batch_qpdf.py 批量移除 pdf 密码脚本,batch remove pdf password
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 | |
from __future__ import print_function | |
import os | |
import sys | |
def main(): | |
dpath_in = os.path.expanduser(r"~/1del/") | |
dpath_out = os.path.expanduser(r"~/1delt/") | |
#download from https://github.com/qpdf/qpdf/releases | |
qpdf = os.path.expanduser(r"~/bin/qpdf") | |
pwd = "123456" | |
for dpath, dnames, fnames in os.walk(dpath_in): | |
for fname in fnames: | |
if fname.lower().endswith(".pdf"): | |
fpath = os.path.join(dpath,fname) | |
reldpath = os.path.relpath(dpath,dpath_in) | |
outdpath = os.path.join(dpath_out,reldpath) | |
outfpath = os.path.join(outdpath,fname) | |
if not os.path.exists(outdpath): | |
print("make new dir: %s"%(outdpath)) | |
os.makedirs(outdpath) | |
cmd = "%s --password='%s' --decrype '%s' '%s'"%(qpdf,pwd,fpath,outfpath) | |
print(cmd) | |
ret = os.system(cmd) | |
if sys.platform=="linux2": | |
ret = ret>>8 | |
if ret!=0: | |
print("error: return %s"%(ret)) | |
if __name__=='__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice!