0
5

More than 1 year has passed since last update.

Python: 複数PDFを結合して1つのPDFに変換する

Last updated at Posted at 2021-12-27
from io import BytesIO
from typing import List
import PyPDF2

def merge_pdfs(pdf_bytes: List[bytes]) -> bytes:
    merger: PyPDF2.PdfFileMerger = PyPDF2.PdfFileMerger()
    try:
        for b in pdf_bytes:
            merger.append(PyPDF2.PdfFileReader(BytesIO(b))) if b else None
        ret: BytesIO = BytesIO()
        merger.write(ret)
        ret.seek(0)
        return ret.read()
    finally:
        merger.close()

bytes <-> File読み書きは割愛。

0
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
5