I am trying to merge a bunch of pdf files into one file. After doing that I need to take that file and merge it with a second file, but it needs to go (page 1 file A, page 1 file B, page 2 file A, page 2 file B, …) I think that I might be close to making that work, but honestly I’ve watched a bunch of videos and a looked at a bunch of tutorials and I’m just lost. Thanks if anyone can help!
import PyPDF2
from PyPDF2 import PdfFileMerger, PdfFileReader
userpdflocation = os.getcwd() + r"\Print Me\"
os.chdir(userpdflocation)
mergedObject = PdfFileMerger()
for fileNumber in range(1, 300):
mergedObject.append(PdfFileReader(‘OPC_’ + str(fileNumber)+ ‘.pdf’, ‘rb’))
mergedObject.write(“mergedfilesoutput.pdf”)
in1=
PyPDF2.PdfFileReader(“mergedfilesoutput.pdf”)
in2=
PyPDF2.PdfFileReader(“OPC_that_need_printing.pdf”)
out = PyPDF2.PdfFileWriter()
for page1, page 2 in zip(in1 .pages, in2.pages):
out.addPage(page1)
out.addPAge(page2)
with opern(‘outpath.pdf’, ‘wb’ as
file:
out.write(file)