I am trying to extract the 6th page from each pdf in a folder in my directory and place each page in a different folder with new file names. I used the following source: Extract specific pages of PDF and save it with Python and Extract pdf for most of my code but I get an error that the file is a string
from PyPDF2 import PdfFileReader, PdfFileWriter
from pathlib import Path
import glob
file_path = 'mypath\*pdf'
new_filepath='mynewfile_path'
file_path=glob.glob(file_path)
i=1
for file in file_path:
input_pdf = PdfFileReader(file)
first_page = input_pdf.getPage(5)
pdf_writer = PdfFileWriter()
i=str(i)
with open(i+ subset.pdf'.format(new_filepath), 'wb') as f:
pdf_writer.write(f)
f.close()
i=int(i)
i+=1