반응형
작성일: 2025년 3월 10일
현재 폴더에 있는 모든 PDF 파일을 1개의 PDF 파일로 합치고 싶다면, 아래의 Python script를 실행하면 된다.
## File name: main.py from PyPDF2 import PdfMerger import os files = os.listdir('./') def merge_pdf_files(): merger = PdfMerger() pdf_files = [x for x in files if x.endswith(".pdf")] [merger.append(pdf) for pdf in pdf_files] with open("merged_pdf_all.pdf", "wb") as new_file: merger.write(new_file) if __name__ == "__main__": merge_pdf_files()
위 Python script를 아래와 같이 실행한다.
(만약 PyPDF2 패키지가 아직 설치되지 않았다면, PyPDF2 패키지를 먼저 설치하고 python script를 실행할 것!)
$ pip3 install PyPDF2 $ python3 main.py
'Python' 카테고리의 다른 글
PDF 파일을 그림 파일(PNG)로 변환하기 (0) | 2025.02.02 |
---|---|
주기적 화면 캡처 및 OCR 적용된 PDF 파일로 변환 (나만의 eBook 만들기) (0) | 2025.01.12 |
Python 온라인 자습서(Tutorial), Reference, Howto, API 문서 (0) | 2024.03.27 |
Python Log Class 및 예제 (0) | 2024.03.26 |
Bind9 Zone 파일의 Serial 변경하는 Python Script, Bash Script (0) | 2024.03.25 |