Created
October 3, 2019 05:21
-
-
Save nyawach/d11e61716aa6ef6ee35e86346328f4a8 to your computer and use it in GitHub Desktop.
PDF結合する
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
import PyPDF2 | |
from pathlib import Path | |
def merge_pdf(sources: list, filename: str): | |
"""PDFを結合する | |
- sources: もととなるソースファイル。配列の順番通りに結合する。 | |
- filename: 出力するファイル名。 | |
""" | |
merger = PyPDF2.PdfFileMerger() | |
for source in sources: | |
merger.append(str(source)) | |
merger.write(filename) | |
merger.close() | |
if __name__ == "__main__": | |
path = Path("./") | |
sources = sorted(list(path.glob("*-A.pdf"))) | |
merge_pdf(sources, './A-Result.pdf') | |
sources = sorted(list(path.glob("*-B.pdf"))) | |
merge_pdf(sources, './B-Result.pdf') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment