New here - couldnt find answer to this but please direct if already answered.
I am looking to create a set of new PDFS by merging a "main" PDF to a list of other "sub" PDFs (say 5 for example) and get an output of 5 pdfs with Main+sub1, Main+sub2.
This is what I have so far. But it is creating 1 pdf with all the pdfs (in the directory) together as one. What I would like is for it to create separate ones as described above - not sure what do add here for it to iterate through each one to do what I want:
import PyPDF2
import glob, os
import shutil
from PyPDF2 import PdfFileMerger
dir="address"
os.chdir(dir)
x = [dir+"/"+a for a in os.listdir(dir) if a.endswith(".pdf")]
print(x)
os.listdir
merger = PdfFileMerger()
for pdf in x:
merger.append(open(pdf, 'rb'))
with open("result.pdf", "wb") as fout:
merger.write(fout)