PythonはPDFファイルを1つのファイルに結合することを実現します

Python を使用して複数の PDF ファイルを 1 つのファイルに結合するには、PyPDF2 パッケージを使用する必要があります。
コードは以下のように表示されます。

!/usr/bin/python
  
import os
from PyPDF2 import PdfFileMerger

target_path = './'

pdf_lst = [f for f in os.listdir(target_path) if f.endswith('.pdf')]
pdf_lst = [os.path.join(target_path, filename) for filename in pdf_lst]

pdf_lst.sort()
file_merger = PdfFileMerger()

for pdf in pdf_lst:
        print pdf
        file_merger.append(pdf)

file_merger.write("./merge.pdf")

おすすめ

転載: blog.csdn.net/yangcunbiao/article/details/125248205