合并
文件
from PyPDF2 import PdfFileMerger
merger = PdfFileMerger()
file_path = "wallex_mt103.pdf"
merger.append(file_path)
merger.append(file_path)
output_pdf_path = "merge.pdf"
merger.write(output_pdf_path)
merger.close()
内存
import io
from PyPDF2 import PdfFileMerger
merger = PdfFileMerger()
file_path = "wallex_mt103.pdf"
merger.append(file_path)
merger.append(file_path)
pdf_obj = io.BytesIO()
merger.write(pdf_obj)
merger.close()
pdf_obj.seek(0)
缩放
from PyPDF2 import PdfFileMerger, PdfFileReader, PdfFileWriter
ok_pdf = "1.pdf"
err_pdf = "2.pdf"
merger_obj = PdfFileMerger()
merger_obj.append(ok_pdf)
render = PdfFileReader(err_pdf)
writer = PdfFileWriter()
pages = render.getNumPages()
for i in range(render.getNumPages()):
page_obj = render.pages[i]
page_obj.scaleTo(595, 842)
writer.addPage(page_obj)
new_err_pdf = "22.pdf"
with open(new_err_pdf, "wb") as fp:
writer.write(fp)
merger_obj.append(new_err_pdf)
pdf_obj = "output.pdf"
merger_obj.write(pdf_obj)
merger_obj.close()
PyPDF2(1.27)
github
doc