import PyPDF2
# 创建一个空的 PDF 文档对象
def pdf_merge(path_a,path_b,path_save):
merged_pdf = PyPDF2.PdfMerger()
# 打开第一个 PDF 文件,读取其内容并追加到新创建的 PDF 文档对象中
with open(path_a, 'rb') as file1:
merged_pdf.append(file1)
# 打开第二个 PDF 文件,读取其内容并追加到新创建的 PDF 文档对象中
with open(path_b, 'rb') as file2:
merged_pdf.append(file2)
# 将合并后的 PDF 写入到新文件中
with open(path_save, 'wb') as merged_file:
merged_pdf.write(merged_file)
path_a = r'A.pdf'
path_b = r'B.pdf'
path_save = r'C.pdf'
pdf_merge(path_a,path_b,path_save)
使用Python合并pdf文件
于 2023-11-21 18:15:16 首次发布