title: Merge PDFs from python list of WindowsPath paths
body: <p>I have an excel file with some data in rows and columns and I am targetting at take the file names from each row and merge those into one pdf file (simply each row to one pdf file)
  This is an example of a list <code>['1', '112238', '112239', '112240', '112337', '112338']</code> the first element in the python list will be the pdf name and the other elements are the file names that is supposed to be existing in directory named <code>Files</code>
  Here's my attempt till now</p>
  <pre><code>from pathlib import Path
  import pandas as pd
  from PyPDF2 import PdfFileMerger
  
  BASE_DIR = Path.cwd()
  MAIN_DIR = BASE_DIR / 'Files'
  FINAL_DIR = BASE_DIR / 'Final'
  
  try:
      shutil.rmtree(FINAL_DIR)
  except:
      pass
  FINAL_DIR.mkdir(parents=True, exist_ok=True)
  
  
  df = pd.read_excel('MainFile.xlsx', dtype = str)
  
  for l in df.T.columns:
      new_list = list(df.T[l][df.T[l].notna()])
      files_list = [MAIN_DIR / f'{i}.pdf' for i in new_list[1:]]
  
      final_list = []
      final_list.append(new_list[0])
  
      for file in files_list:
          if file.exists():
              final_list.append(file)
          else:
              print(f'{file} ---&gt; NOT Exists')
  
      merger = PdfFileMerger()
      for pdf in final_list[1:]:
          merger.append(pdf)
  
      merger.write(FINAL_DIR / f'{final_list[0]}.pdf')
      merger.close()
  </code></pre>
  <p>Here's a snapshot of the excel file that I read the file names from</p>
  <p><a href="https://i.stack.imgur.com/m4fVA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/m4fVA.png" alt="enter image description here" /></a></p>
  <p>and the pdf files in directory named <code>Files</code></p>
  <p>When I tried to run the script, I encountered an error like that</p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:\Users\Future\Desktop\demo.py&quot;, line 33, in &lt;module&gt;
      merger.append(pdf)
    File &quot;C:\Users\Future\AppData\Local\Programs\Python\Python39\lib\site-packages\PyPDF2\merger.py&quot;, line 203, in append
      self.merge(len(self.pages), fileobj, bookmark, pages, import_bookmarks)
    File &quot;C:\Users\Future\AppData\Local\Programs\Python\Python39\lib\site-packages\PyPDF2\merger.py&quot;, line 133, in merge
      pdfr = PdfFileReader(fileobj, strict=self.strict)
    File &quot;C:\Users\Future\AppData\Local\Programs\Python\Python39\lib\site-packages\PyPDF2\pdf.py&quot;, line 1084, in __init__
      self.read(stream)
    File &quot;C:\Users\Future\AppData\Local\Programs\Python\Python39\lib\site-packages\PyPDF2\pdf.py&quot;, line 1689, in read
      stream.seek(-1, 2)
  AttributeError: 'WindowsPath' object has no attribute 'seek'
  </code></pre>
  <p>I have tried this modification <code>merger.append(str(Path(pdf)))</code> and it seems to skip the first problem (I am not sure) but now I got another error</p>
  <pre><code>PdfReadWarning: Xref table not zero-indexed. ID numbers for objects will be corrected. [pdf.py:1736]
  Traceback (most recent call last):
    File &quot;C:\Users\Future\Desktop\demo.py&quot;, line 39, in &lt;module&gt;
      merger.write(FINAL_DIR / f'{str(final_list[0])}.pdf')
    File &quot;C:\Users\Future\AppData\Local\Programs\Python\Python39\lib\site-packages\PyPDF2\merger.py&quot;, line 230, in write
      self.output.write(fileobj)
    File &quot;C:\Users\Future\AppData\Local\Programs\Python\Python39\lib\site-packages\PyPDF2\pdf.py&quot;, line 487, in write
      stream.write(self._header + b_(&quot;\n&quot;))
  AttributeError: 'WindowsPath' object has no attribute 'write'
  </code></pre>