10 PyPDF2

10.1 项目简介

使用Python读写PDF的实用程序

10.2 项目地址

https://github.com/mstamy2/PyPDF2

10.3 文档地址

https://pythonhosted.org/PyPDF2/

10.4 最佳实践

pip3 install pypdf2
from PyPDF2 import PdfFileReader,PdfFileWriter

def merge_pdf(pdfs, out):
    pdf_writer = PdfFileWriter()
    page_count = 0
    for pdf_path in pdfs:
        pdf_reader = PdfFileReader(pdf_path)
        page_count += pdf_reader.getNumPages()
        for page in range(pdf_reader.getNumPages()):
            pdf_writer.addPage(pdf_reader.getPage(page))

    with open(out,'wb') as out:
        pdf_writer.write(out)
    print(f'合并完成,共{page_count}页')

merge_pdf(['pdf/01.pdf','pdf/02.pdf'],'pdf/合并1.pdf')


© pengpeng 本站总访问量修改时间: 2020-07-26

results matching ""

    No results matching ""