简体   繁体   中英

PyPDF2 throws error when merging (Python3.3/Win7)

I'm using PyPDF2 to do a simple merge of PDFs. I wrote the code on XP/Python 3.2 and it works fine. When I moved it to Win7-64bit/Python 3.3 and used the latest PyPDF2 distribution ( https://github.com/knowah/PyPDF2/ ) it throws the following error when appending a PDF to the merger object:

Traceback (most recent call last):
  File "C:\PDFs\pdfmerge2.py", line 103, in <module>
    count=merge_and_check(l_batch_files)
  File "C:\PDFs\pdfmerge2.py", line 47, in merge_and_check
    merger.append(pf)
  File "C:\Python33\lib\site-packages\PyPDF2\merger.py", line 168, in append
    self.merge(len(self.pages), fileobj, bookmark, pages, import_bookmarks)
  File "C:\Python33\lib\site-packages\PyPDF2\merger.py", line 97, in merge
    elif type(fileobj) == file:
NameError: global name 'file' is not defined

I've tried clean installs using Python 3.2 and get the same error.

What's weird is that merger.py is very different between my XP install and Win7, but I can't find a reference to an earlier version of PyPDF2 and I can't remember where I downloaded that version from, though I do know it was on 18/12/12. There were no updates to PyPDF2 between then and now from what I can see.

The install on Win7 used the standard 'python setup.py build' then 'install'.

Any ideas?

Try import io module and then create stream with method FileIO()

example:

import io
.
.
.
.
outputStream = io.FileIO('c:\example.pdf', 'wb')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM