简体   繁体   English

合并时PyPDF2引发错误(Python3.3 / Win7)

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

I'm using PyPDF2 to do a simple merge of PDFs. 我正在使用PyPDF2进行PDF的简单合并。 I wrote the code on XP/Python 3.2 and it works fine. 我在XP / Python 3.2上编写了代码,效果很好。 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: 当我将其移至Win7-64bit / Python 3.3并使用最新的PyPDF2发行版( https://github.com/knowah/PyPDF2/ )时,将PDF附加到合并对象时会引发以下错误:

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. 我尝试使用Python 3.2进行全新安装,并得到相同的错误。

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. 奇怪的是,我的XP安装程序和Win7之间的merge.py有很大不同,但是我找不到对较早版本的PyPDF2的引用,而且我不记得我从哪里下载了该版本,尽管我确实知道在12/12/18。 There were no updates to PyPDF2 between then and now from what I can see. 据我所知,从那时到现在,PyPDF2没有更新。

The install on Win7 used the standard 'python setup.py build' then 'install'. Win7上的安装使用标准的“ python setup.py build”,然后使用“ install”。

Any ideas? 有任何想法吗?

Try import io module and then create stream with method FileIO() 尝试导入io模块,然后使用FileIO()方法创建流

example: 例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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