问题
I have been creating a program in Python for merging 2 pdf files into a single file. Here is the code:-
import os
from PyPDF2 import PdfFileMerger
source_dir = os.getcwd()
merger = PdfFileMerger()
for item in os.listdir(source_dir):
if item.endswith('pdf'):
merger.append(item)
merger.write('completed_file.pdf')
merger.close()
while running the code i encountered the following error:-
"F:\Python folder\Pdf_Merger\venv\Scripts\python.exe" "F:/Python folder/Pdf_Merger/main.py"
Traceback (most recent call last):
File "F:\Python folder\Pdf_Merger\venv\lib\site-packages\PyPDF2\pdf.py", line 1147, in getNumPages
self.decrypt('')
File "F:\Python folder\Pdf_Merger\venv\lib\site-packages\PyPDF2\pdf.py", line 1987, in decrypt
return self._decrypt(password)
File "F:\Python folder\Pdf_Merger\venv\lib\site-packages\PyPDF2\pdf.py", line 1996, in _decrypt
raise NotImplementedError("only algorithm code 1 and 2 are supported")
NotImplementedError: only algorithm code 1 and 2 are supported
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "F:\Python folder\Pdf_Merger\main.py", line 10, in <module>
merger.append(item)
File "F:\Python folder\Pdf_Merger\venv\lib\site-packages\PyPDF2\merger.py", line 203, in append
self.merge(len(self.pages), fileobj, bookmark, pages, import_bookmarks)
File "F:\Python folder\Pdf_Merger\venv\lib\site-packages\PyPDF2\merger.py", line 139, in merge
pages = (0, pdfr.getNumPages())
File "F:\Python folder\Pdf_Merger\venv\lib\site-packages\PyPDF2\pdf.py", line 1150, in getNumPages
raise utils.PdfReadError("File has not been decrypted")
PyPDF2.utils.PdfReadError: File has not been decrypted
Process finished with exit code 1
来源:https://stackoverflow.com/questions/64856980/notimplementederror-only-algorithm-code-1-and-2-are-supported-in-pypdf2