PyPDF2.py 合并pdf时报错问题
报错如下:
Traceback (most recent call last):
File "./pdf_merge.py", line 68, in <module>
main(sys.argv[1], sys.argv[2])
File "./pdf_merge.py", line 51, in main
blankpage.mergeTranslatedPage(pageobj, 0, 0)
File "/Users/root/Library/Python/2.7/lib/python/site-packages/PyPDF2/pdf.py", line 2377, in mergeTranslatedPage
tx, ty], expand)
File "/Users/root/Library/Python/2.7/lib/python/site-packages/PyPDF2/pdf.py", line 2328, in mergeTransformedPage
PageObject._addTransformationMatrix(page2Content, page2.pdf, ctm), ctm, expand)
File "/Users/root/Library/Python/2.7/lib/python/site-packages/PyPDF2/pdf.py", line 2284, in _mergePage
page2Content, rename, self.pdf)
File "/Users/root/Library/Python/2.7/lib/python/site-packages/PyPDF2/pdf.py", line 2189, in _contentStreamRename
op = operands[i]
KeyError: 0
解决:
- 打开 /Users/root/Library/Python/2.7/lib/python/site-packages/PyPDF2/pdf.py
- 在文件开头加上
import types - 找到函数
_contentStreamRename
修改函数:
def _contentStreamRename(stream, rename, pdf):
if not rename:
return stream
stream = ContentStream(stream, pdf)
for operands, operator in stream.operations:
# for i in range(len(operands)):
# op = operands[i]
# if isinstance(op, NameObject):
# operands[i] = rename.get(op,op)
if type(operands) == types.ListType:
for i in range(len(operands)):
op = operands[i]
if isinstance(op, NameObject):
operands[i] = rename.get(op,op)
elif type(operands) == types.DictType:
for i in operands:
op = operands[i]
if isinstance(op, NameObject):
operands[i] = rename.get(op,op)
else:
raise KeyError("type of operands is %s" % type(operands))
return stream
_contentStreamRename = staticmethod(_contentStreamRename)
参考链接:https://github.com/mstamy2/PyPDF2/issues/196
PyPDF2.py 合并pdf时报错问题的更多相关文章
- word 转 PDF时报错
利用微软自带的com组件,把word转化成Pdf,利用vs2012调试时没有问题,但是发布到IIS时出错,错误为: 检索 COM 类工厂中 CLSID 为 {} 的组件时失败,原因是出现以下错误: 8 ...
- django 运行python manage.py sqlall books 时报错 app has migration
出现这个问题的原因是版本之前的不兼容,我用的django版本是1.8.6 而 这条python manage.py sqlall books 是基于django1.0版本的. 在django1.8.6 ...
- py+selenium运行时报错Can not connect to the Service IEDriverServer.exe
问题: 运行用例时,出现报错(host文件已加入127.0.0.1 localhost): raise WebDriverException("Can not connect to the ...
- 使用PyPdf2合并PDF文件(没有空白、报错)
使用PyPdf2合并PDF文件(没有空白.报错) 对于合并之后pdf空白,或者出现 'latin-1' codec can't encode characters in position 8-11: ...
- pypdf2:下载Americanlife网页生成pdf合并pdf并添加书签
初步熟悉 安装 pip install pypdf2 合并并添加书签 #!/usr/bin/env python3.5 # -*- coding: utf-8 -*- # @Time : 2019/1 ...
- python 运行python manege.py runserver时报错:“no module named djangorestframework” 的解决方案
python 运行python manege.py runserver时报错:“no module named djangorestframework” 的解决方案 importerror:no mo ...
- 配置python+mod_wsgi+apache 时 在浏览器中访问服务器时报错:Invalid HTTP_HOST header: 'XXXXX'. You may need to add u'XXXXX' to ALLOWED_HOSTS,在setting.py中添加‘*”无效的原因
配置python+mod_wsgi+apache 时 在浏览器中访问服务器时报错:Invalid HTTP_HOST header: 'XXXXX'. You may need to add u'XX ...
- 执行python manage.py makemigrations时报错TypeError: __init__() missing 1 required positional argument: 'on_delete'
在执行python manage.py makemigrations时报错: TypeError: __init__() missing 1 required positional argument: ...
- 使用Python批量合并PDF文件(带书签功能)
网上找了几个合并pdf的软件,发现不是很好用,一般都没有添加书签的功能. 又去找了下python合并pdf的脚本,发现也没有添加书签的功能的. 于是自己动手编写了一个小工具,使用了PyPDF2. 下面 ...
随机推荐
- navigator导航页面跳转与绑定事件
效果图: 1. 新建一个index页面 主页面分为两块,上面是导航条,下面是轮播图. 导航条: <view class='menu'> <scroll-view scroll-x&g ...
- eladmin-plus V2.0.0 发布,单表链式调用更丝滑
一.项目简介 eladmin的mybatis-plus版本,单表使用链式调用,代码更简洁,调用更便捷.目前更新到2021年7月.项目基于 Spring Boot 2.4.2 . Mybatis-plu ...
- Java 在线/离线 文档
英文: Oracle 官网在线文档 Java SE 8 Oracle 官网在线文档 Java SE 9 & JDK 9 中文: Java 1.8: 中文 – 谷歌版 中文 – 有道版 中文 – ...
- Python小白的数学建模课-10.微分方程边值问题
小白往往听到微分方程就觉得害怕,其实数学建模中的微分方程模型不仅没那么复杂,而且很容易写出高水平的数模论文. 本文介绍微分方程模型边值问题的建模与求解,不涉及算法推导和编程,只探讨如何使用 Pytho ...
- 对HashMap的一次记录
HashMap的具体学习,认识了解. 前言 也是最近开始面试才发现,HashMap是问的真多.以前听学长或自己在网上看到过一些面试资料都在说集合.线程这块比较重要,面试的重点.自己也是有那抵触情绪,所 ...
- 数据结构算法学习之队列(数组模拟java实现)
数组模拟队列 数组模拟队列 今天学习数组模拟队列.队列常用于生活中的方方面面.比如银行叫号排队.实际上就是队列.所有人抽号排队.先去的先抽号.所以靠前的号最后会先被叫到然后出队.后边的会随之往前移位. ...
- Java互联网架构师系统进阶课程学习 (4)【享学】
Java互联网架构师系统进阶课程学习 (4)[享学] 4.显式锁和AQS 显式锁 Lock接口和核心方法 Lock接口和synchronized的比较 synchronized 代码简洁,Lock ...
- vue 源码详解(一):原型对象和全局 `API`的设计
vue 源码详解(一):原型对象和全局 API的设计 1. 从 new Vue() 开始 我们在实际的项目中使用 Vue 的时候 , 一般都是在 main.js 中通过 new Vue({el : ' ...
- linux笔记全(无图版)
1.ls 查看当前目录下的所有内容 黑色的是文件,蓝色的是文件夹,也就是目录 2.rm -f anaconda-ks. cfg 彻底删除文件(如不确定,则需要先保存备份,也就是快照) 3.ifconf ...
- Java后端编译
概述 如果我们把字节码看作是程序语言的一种中间表示形式(Intermediate Representation,IR)的话, 那编译器无论在何时.在何种状态下把Class文件转换成与本地基础设施(硬件 ...