Skip to content

Commit

Permalink
update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
dothinking committed Jun 7, 2022
1 parent 6306931 commit 5c19801
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 723 deletions.
22 changes: 16 additions & 6 deletions docs/2021-01-02-Python处理PDF的第三方库对比.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ tags: [python]

---

*2022.06.07修订:新增第三方库`borb`。初稿写于2021.01.02,彼时`borb`才发布1.0版没几个月;两年不到,Github上已近三千赞。*

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

## 概况

功能对比从大粒度上分成了`提取内容``操作页面``创建内容`三方面。前两者分别是针对已经存在的PDF文档的读和写操作,最后一项从内容上创建新文档。考虑到时效性,以下对比列出了撰文时相应的最新版本
功能对比从大粒度上分成了 **提取内容****操作页面****创建内容** 三方面。前两者分别是针对已经存在的PDF文档的读和写操作,最后一项从内容上创建新文档。考虑到时效性,以下对比列出了撰文时(2021.01)相应的最新版本

- `提取内容`如文本、图片、元信息
- `操作页面`特指操作已经存在的页面例如分割、合并、裁剪、旋转等
- `创建内容`指创建或修改页面内容,例如文本、图片、形状
- **提取内容** 如文本、图片、元信息
- **操作页面** 特指操作已经存在的页面例如分割、合并、裁剪、旋转等
- **创建内容** 指创建或修改页面内容,例如文本、图片、形状


Python库 | 当前版本 | Python版本 | 开源协议 | 最新更新 | 功能:提取内容 | 功能:操作页面 | 功能:创建内容 | 备注
Expand All @@ -28,15 +30,23 @@ Python库 | 当前版本 | Python版本 | 开源协议 | 最新更新 | 功能
[pdfplumber](https://github.com/jsvine/pdfplumber) | 0.5.25 | 3.6-3.8 | MIT | 活跃 | √ | × | × | 基于`pdfminer.six`;除了文本、形状(矩形、直线/曲线),还能**解析表格***几个提取PDF表格的Python库的对比参考[此处](https://github.com/atlanhq/camelot/wiki/Comparison-with-other-PDF-Table-Extraction-libraries-and-tools#pdf-table-extract)*
[pdfminer.six](https://github.com/pdfminer/pdfminer.six) | 20201018 | 3.6+ | MIT | 2个月前 | √ | × | × | [`pdfminer`](https://github.com/euske/pdfminer/)的社区维护版,因为`pdfminer`自2020年起不再积极维护
[PyMuPDF](https://github.com/pymupdf/PyMuPDF) | 1.18.5 | 3.6+ | GPL V3 | 非常活跃 | √ | √ | √ | 基于[`mupdf`](https://mupdf.com/);以处理速度著称,参考[此处](https://pymupdf.readthedocs.io/en/latest/app1.html)
[borb](https://github.com/jorisschellekens/borb) | 2.0.27 | 3.6+ | AGPL | 非常活跃 | √ | √ | √ | 纯Python库,支持读、写、操作PDF文档,兼顾底层和高级应用

*`borb`于 2022.06 新加入对比,时间点以此为准。*

## 点评

- `PyPDF2`系列、`pdfrw``pikepdf`专注对已经存在的PDF的操作(分割、合并、旋转等),前两者基本处于停止维护的状态。

- `pdfplumber`及其依赖`pdfminer.six`专注PDF内容提取,例如文本(位置、字体及颜色等)和形状(矩形、直线、曲线),前者还有解析表格的功能。

- `ReportLab`专注PDF页面内容(文本、图、表等)的创建。
- `PyMuPDF`功能全面且速度快,但是`GPL v3`的开源协议对商用不友好。

- `PyMuPDF``borb`同时支持读、写及PDF页面操作,功能最为全面。其中,`PyMuPDF`尤其以速度快著称,而`borb`是新开发并深得好评的库,潜力无穷。但是,二者同为`GPL`家族的开源协议,对商用不太友好*

`*` *支持免费使用,但是要求引用其的程序也必须遵守相应协议即开源。如果需要闭源使用的话,需要向作者申请付费的商用授权。*


最后,用下图的总结结束全文。

![](images/2021-01-02-01.png)
![](images/2021-01-02-01.drawio.png)
4 changes: 2 additions & 2 deletions docs/2022-01-27-GitLab-CI-CD:触发跨项目pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tags: [GitLab]

为简化表述,用`A`表示发布仓库,分别用`B1``B2`表示前、后端仓库,则可用下图表示以上流程。

![general-flow](images/2022-01-27-01.png)
![general-flow](images/2022-01-27-01.drawio.png)


## 具体流程
Expand All @@ -43,7 +43,7 @@ tags: [GitLab]

类似上文所述`A`的流程,只不过此时需要根据原始仓库(即`B1`)确定只触发`B1`的流程,进而来到`B1``build`

![detail-flow](images/2022-01-27-02.png)
![detail-flow](images/2022-01-27-02.drawio.png)


## 最终效果
Expand Down
Binary file added docs/images/2021-01-02-01.drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/2021-01-02-01.png
Binary file not shown.
Binary file added docs/images/2022-01-27-01.drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/2022-01-27-01.png
Binary file not shown.
Binary file added docs/images/2022-01-27-02.drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/2022-01-27-02.png
Binary file not shown.
Loading

0 comments on commit 5c19801

Please sign in to comment.