0

I have some pdf files which are uploaded on a remote server. I have URL for each file and we can download these PDF files by visiting those URLs.

My question is,

I want to merge all pdf files into a single file (but, without storing these files into local directory). How can I do that (in python module 'PyPDF2')?

Prathmesh
  • 57
  • 6

1 Answers1

0

Please move to pypdf. It's essentially the same as PyPDF2, but the development will continue there (I'm the maintainer of both projects).

Your question is answered in the docs:

Instead of writing to a file, you write to io.ByteIO stream:

from io import ByteIO

# e.g. writer = PdfWriter()
# ... do what you want to do with the PDFs

with BytesIO() as bytes_stream:
    writer.write(bytes_stream)
    bytes_stream.seek(0)
    data = bytes_stream.read()  # that is now the "bytes" represention
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958