本文作者:王碧琪
文字编辑:方 言
技术总编:张 邯
在之前的推文《提取PDF文本信息:入门》中,我们使用pdfminer提取了PDF文档中的文本信息,相较之下,今天要介绍的pdfplumber提取文本信息所使用的程序更加简洁,处理方式更直接,一起来学习一下吧~
一、简介
待处理的PDF文档内容如下图示:
pdfplumber中的extract_text
函数就可以实现提取文本信息的功能。官方文档如下:
.extract_text(x_tolerance=0, y_tolerance=0)
Collates all of the page's character objects
into a single string. Adds spaces where the difference between the x1 of one character and the x0 of the next is greater than x_tolerance. Adds newline characters where the difference between the doctop of one character and the doctop of the next is greater than y_tolerance.