I'm writing a python script to merge multiple PDFs into one to put into an output folder. Each PDF will be in a different folder with an employee name on it and it will need to be combined with the corresponding pdf in another folder. Not all employees will have each file so I included that in the logic.
The problem I am having currently is that PdfFileMerger expects a string when appending files and the pathlib library returns a windowpath object. That will not easily convert to a string. I'm getting this information about PyPDF2 from this post pypdf Merging multiple pdf files into one pdf. I'm new to the pathlib library is there a conversion I should be doing or should I be getting a different path object?
from PyPDF2 import PdfFileMerger, PdfFileReader
from pathlib import Path
tc = Path('totalcomp')
merger = PdfFileMerger()
for i in tc.iterdir():
pdfs = []
try:
pdfs.append(Path(f'profitshare/{i.name}'))
pdfs.append(Path(f'merit/{i.name}'))
finally:
pdfs.append(i)
for pdf in pdfs:
output = i.name
merger.append(pdf, 'rb')
merger.write(Path(f'/output/{i.name}'))