

Pdf_buffer_1 = StringIO.StringIO().write(pdf_content_1) Pdf_content_1 = requests.get(' pdf_content_2 = requests.get(' # Write to in-memory file-like buffers The example: from PyPDF2 import PdfFileMerger, PdfFileReader Specifically, it generalizes the solution to any HTTP-accessible PDF. This eliminates the assumed step of downloading the PDF to begin with, and allows us to generalize beyond the simple case of both PDFs existing on disk. & we can fetch both PDFs from remote locations and merge them together in memory in one-fell-swoop. If the 2 PDFs do not exist on your local machine, and instead are normally accessed/download via a URL (i.e. rgePage(file2.getPage(specificPageIndex)) file1 = PdfFileReader(file(filename1, "rb")) Will be drawn after, or “on top” of this page. The parameter page’s content stream willīe added to the end of this page’s content stream, meaning that it Merges the content streams of two pages into one.

OutputStream = file("document-output.pdf", "wb") Output.addPage(file2.getPage(specificPageIndex)) Output.addPage(file1.getPage(specificPageIndex)) file1 = PdfFileReader(file(filename1, "rb"))įile2 = PdfFileReader(file(filename2, "rb"))

Merger.append(PdfFileReader(file(filename2, 'rb')))Īnd to append specific pages of different PDF files, use the PdfFileWriter class with the addPage method.Īdds a page to this PDF file. Merger.append(PdfFileReader(file(filename1, 'rb'))) Here's one way to do it taken from pypdf Merging multiple pdf files into one pdf: from PyPDF2 import PdfFileMerger, PdfFileReader Identical to the merge() method, but assumes you want to concatenateĪll pages onto the end of the file instead of specifying a position. Using the PdfFileMerger class and its append method. What you are (were) looking for is really appending two files/pages into a new file.

What you're describing in your question is really the intended use of mergePage which should be called applyPageOnTopOfAnother but that's a little long. Most people call the appending action a merge but it's not. As I'm searching the web for python pdf merging solution, I noticed that there's a general misconception with merging versus appending.
