this pdf splitter program I want to do some modifications in this like when I give any pdf to split it creates the folder by that pdf name and store all pdf in that folder.. when I try to do that, the program gives an error [permission denied ]. please help me !!
** This is my code **
# pdf_splitter.py
import os
from PyPDF2 import PdfFileReader, PdfFileWriter
def pdf_splitter(path):
fname = os.path.splitext(os.path.basename(path))[0]
pdf = PdfFileReader(path)
for page in range(pdf.getNumPages()):
pdf_writer = PdfFileWriter()
pdf_writer.addPage(pdf.getPage(page))
output_filename = '{}_page_{}.pdf'.format(
fname, page+1)
with open(output_filename, 'w') as out:
pdf_writer.write(out)
print('Created: {}'.format(output_filename))
if __name__ == '__main__':
path = input("Enter Path : ")
foldername=path.split('.')[0]
cwd = os.getcwd()
try:
os.mkdir(foldername)
except:
pass
outputpath = os.path.join(cwd,foldername)
pdf_splitter(outputpath)
**I got this error**
```
PS D:\Downloads\pdf> & C:/Python310/python.exe d:/Downloads/pdf/pdf.py
Enter Path : demo.pdf
Traceback (most recent call last):
File "d:\Downloads\pdf\pdf.py", line 40, in <module>
pdf_splitter(outputpath)
File "d:\Downloads\pdf\pdf.py", line 10, in pdf_splitter
pdf = PdfFileReader(path)
File "C:\Python310\lib\site-packages\PyPDF2\pdf.py", line 1081, in __init__
fileobj = open(stream, 'rb')
PermissionError: [Errno 13] Permission denied: 'D:\\Downloads\\pdf\\demo'