python常用PDF库总结

使用Python操作PDF:常用PDF库总结

PDF(Portable Document Format)是一种便携文档格式,便于跨操作系统传播文档。PDF文档遵循标准格式,因此存在很多可以操作PDF文档的工具,Python自然也不例外。本文从功能、开源协议及社区活跃度三方面对比7个常用的Python第三方库,以便根据具体需求选择合适的库。

常见PDF库
PyPDF2 (已不再维护,继任者PyPDF4)
由于PyPDF2似乎更知名,故本文以其作为条目列出。

PyPDF、PyPDF2及PyPDF4的渊源[1]。
pdfrw
自身不能创建新内容,但是集成了ReportLab,可以兼容ReportLab生成新页面。

ReportLab
商业版的开源版本,专业创建PDF内容如文本、图表等。

pikepdf
基于C++的QPDF,对标PyPDF2和pdfrw;偏向PDF底层。

pdfplumber
基于pdfminer.six,除了读取文本、形状(矩形、直线/曲线)外,还能解析表格。

几个提取PDF表格的Python库的对比[2]。
pdfminer.six
pdfminer的社区维护版(pdfminer自2020年起不再积极维护)。

PyMuPDF
基于mupdf,功能全面,并以处理速度著称[3]。

对比
本文将Python操作PDF的能力从大粒度上分成提取内容、操作页面和创建内容三方面。前两者分别是针对已经存在的PDF文档的读和写操作,最后一项从内容上创建新文档。

提取内容:如文本、图片、元信息
操作页面:特指操作已经存在的页面,例如分割、合并、裁剪、旋转等
创建内容:指创建或修改页面内容,例如文本、图片、形状考虑到时效性,以下对比列出了撰写本文时相应的最新版本。

[公式]

总结
PyPDF2系列、pdfrw及pikepdf专注对已经存在的PDF的操作(分割、合并、旋转等),前两者基本处于停止维护的状态。
pdfplumber及其依赖pdfminer.six专注PDF内容提取,例如文本(位置、字体及颜色等)和形状(矩形、直线、曲线),前者还有解析表格的功能。
ReportLab专注PDF页面内容(文本、图、表等)的创建。
PyMuPDF功能全面且速度快,但是GPL v3的开源协议对商用不太友好。
最后以下图结束本文。

PDF库功能对比

在这里插入图片描述

  • 3
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python is an extensible, interpreted, object-oriented programming language. It supports a wide range of applica- tions, from simple text processing scripts to interactive Web browsers. Python 是一种可扩展的, 即译式, 面向对象规格的编程语言. 它能应用在极广泛的地方, 从简单的文字处理 工作到交互式的网页浏览器. While the Python Reference Manual describes the exact syntax and semantics of the language, it does not describe the standard library that is distributed with the language, and which greatly enhances its immediate usability. This library contains built-in modules (written in C) that provide access to system functionality such as file I/O that would otherwise be inaccessible to Python programmers, as well as modules written in Python that provide standardized solutions for many problems that occur in everyday programming. Some of these modules are explicitly designed to encourage and enhance the portability of Python programs. Python 语言参考手册 中精确地描述了Python 语言的句法及语义. 然而语言参考手册中没有提到Python 所 附带功能强大的标准. 这个函式大大地增强了Python 的实用性. 其中包括C 写的内建模组, 提供介面 让程式进行操作系统层次的工作, 例如档案的输出输入; 同时也有以Python 语言本身编写的模组, 为实际 编程时常遇的问题提供标准解决方案. 这类模组有的经过特别设计以便Python 程式在跨平台的情况下运 行无误. This library reference manual documents Python’s standard library, as well as many optional library modules (which may or may not be available, depending on whether the underlying platform supports them and on the configuration choices made at compile time). It also documents the standard types of the language and its built-in functions and exceptions, many of which are not or incompletely documented in the Reference Manual. 本参考手册罗列并说明了Python 标准的各种功能, 以及许多非核心的模组(按不同的操作系统和编译时 的设置而定, 不是每台机上的Python 都能用这些模组.) 本手册同时记载了Python 语言所有的标准数据类 型, 内建函数, 异常类, 这些在参考手册中被忽略了或只是扼要的提过一下. This manual assumes basic knowledge about the Python language. For an informal introduction to Python, see the Python Tutorial; the Python Reference Manual remains the highest authority on syntactic and semantic questions. Finally, the manual entitled Extending and Embedding the Python Interpreter describes how to add new extensions to Python and how to embed it in other applications. 本手册的读者要对Python 有基本的认识. 初学者应该从Python 指南 开始. 至于Python 语言参考手册 则是该语言的语法和语义问题上的权威阐释. 最后 扩展或嵌入 Python 解释器 一文解说了如何在Python 中加入新的扩展模组; 以及怎样把Python 解释器嵌入到其他的应用程式中.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值