Created
July 27, 2021 14:29
-
-
Save rkdgusrnrlrl/c7d33aa2a2df34f73da207eb6255b8b4 to your computer and use it in GitHub Desktop.
pdf 암호 제거 및 병합 하는 기능 함수(pikepdf, PyPDF2 라이브러리 설치 필요)
This file contains 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
import pikepdf | |
import os | |
from PyPDF2 import PdfFileMerger | |
# pip install pikepdf | |
# pip install PyPDF2 | |
def pdf_merge(key_file_names, dir_path): | |
ff = os.listdir(dir_path) | |
for fk in key_file_names: | |
pdf_merger = PdfFileMerger(strict=False) | |
for file_name in ff: | |
if fk in file_name: | |
pdf_merger.append(f'non_pwd/{file_name}') | |
pdf_merger.write(f"{fk}.pdf") | |
pdf_merger.close() | |
def remove_pwd(file_name, pwd): | |
with pikepdf.open(file_name, password=pwd) as pdf: | |
pdf.save(f"non_pwd/{file_name}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment