Python IOError:[Errno 22]参数无效
我试图使用PyPDF2库将所有pdf连接成一个pdf。 我使用Python2.7实现同样的功能 我的错误是:Python IOError:[Errno 22]参数无效,python,pypdf2,Python,Pypdf2,我试图使用PyPDF2库将所有pdf连接成一个pdf。 我使用Python2.7实现同样的功能 我的错误是: >>> RESTART: C:\Users\Yash gupta\Desktop\first projectt\concatenate\test\New folder\test.py ['Invoice.pdf', 'Invoice_2.pdf', 'invoice_3.pdf', 'last.pdf'] Traceback (most recent call l
>>>
RESTART: C:\Users\Yash gupta\Desktop\first projectt\concatenate\test\New folder\test.py
['Invoice.pdf', 'Invoice_2.pdf', 'invoice_3.pdf', 'last.pdf']
Traceback (most recent call last):
File "C:\Users\Yash gupta\Desktop\first projectt\concatenate\test\New folder\test.py", line 17, in <module>
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
File "C:\Python27\lib\site-packages\PyPDF2\pdf.py", line 1084, in __init__
self.read(stream)
File "C:\Python27\lib\site-packages\PyPDF2\pdf.py", line 1689, in read
stream.seek(-1, 2)
IOError: [Errno 22] Invalid argument
我的pdf有一些非ASCII字符,所以我使用“r”而不是“rb”
PS:我对Python和所有这些库都不熟悉,我相信你在错误地循环收集的文件,Python是缩进敏感的
# Loop through all the PDF files.
for filename in pdfFiles:
pdfFileObj = open(filename, 'rb')
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
# Loop through all the pages
for pageNum in range(0, pdfReader.numPages):
pageObj = pdfReader.getPage(pageNum)
pdfWriter.addPage(pageObj)
# Save the resulting PDF to a file.
pdfOutput = open('last.pdf', 'wb')
pdfWriter.write(pdfOutput)
pdfOutput.close()
此外,如果要合并PDF文件,请尝试使用PdfileMerger:
merger = PdfFileMerger(strict=False)
.谢谢,但现在这个错误来自文件C:\Python27\lib\site packages\PyPDF2\generic.py,第585行,在readFromStream%utils.hexStrstream.tell中,key pdfReader错误:字典中的多个定义位于字节0x2695处,关于key/Type,您能帮助吗???@YashGupta更新了我的答案。
merger = PdfFileMerger(strict=False)