没有合适的资源?快使用搜索试试~ 我知道了~
首页PDFPlumber:从PDF文件提取文字和表格的Python库.pdf
PDFPlumber:从PDF文件提取文字和表格的Python库.pdf
1星 需积分: 48 60 下载量 49 浏览量
更新于2023-03-03
评论 3
收藏 1004KB PDF 举报
pdf格式存在的,比如:论文,技术文档,标准文件,书籍等。pdf格式使机器提取信息格外困难。 pdf的文本和表格处理用多种方式可以实现, 本文介绍pdfplumber对文本和表格提取。这个库在GitHub上星600多,不过使用起来很方便, 效果也很好,可以满足对pdf中信息的提取需求。
资源详情
资源评论
资源推荐
4/21/2020 PDFPlumberPDFPython - Python | CTOLib
PDF generated with the free version of http://www.html2pdf.solutions
53
53
2061
2061
v0.5.15
v0.5.15
> Python>
PDFPlumberPDFPython
Plumb a PDF for detailed information about each char, rectangle, line, et cetera —and easily extract text and tables.
Plumb a PDF for detailed information about each text character, rectangle, and line. Plus: Table extraction and visual
debugging.
Works best on machine-generated, rather than scanned, PDFs. Built on pdfminer and pdfminer.six.
Currently tested on Python 2.7, 3.1, 3.4, 3.5, and 3.6.
Installation
Command line interface
Python library
Visual debugging
Extracting tables
Extracting form values
Demonstrations
Acknowledgments / Contributors
Contributing
pip install pdfplumber
To use pdfplumber's visual-debugging tools, you'll also need to have ImageMagick installed on your computer. Installation
instructions here.
curl "https://cdn.rawgit.com/jsvine/pdfplumber/master/examples/pdfs/background-checks.pdf" > background-checks.pdf
pdfplumber < background-checks.pdf > background-checks.csv
The output will be a CSV containing info about every character, line, and rectangle in the PDF.
Argument Description
Ad
Go beyond APM
The all-in-one software
intelligence platform.
Sign Up
Ad
Dynatrace
PDFPlumber v0.5.13
Table of Contents
Installation
Command line interface
Basic example
Options
4/21/2020 PDFPlumberPDFPython - Python | CTOLib
PDF generated with the free version of http://www.html2pdf.solutions
--format [format] csv or json. The json format returns slightly more information; it includes PDF-level metadata
and height/width information about each page.
--pages [list of pages]
A space-delimited, 1-indexed list of pages or hyphenated page ranges. E.g., 1, 11-15, which
would return data for pages 1, 11, 12, 13, 14, and 15.
--types [list of object
types to extract]
Choices are char, anno, line, curve, rect, rect_edge. Defaults to char, anno, line, curve, rect.
import pdfplumber
with pdfplumber.open("path/to/file.pdf") as pdf:
first_page = pdf.pages[0]
print(first_page.chars[0])
pdfplumber provides two main ways to load a PDF:
pdfplumber.open("path/to/file.pdf")
pdfplumber.load(file_like_object)
Both methods return an instance of the pdfplumber.PDF class.
To load a password-protected PDF, pass the password keyword argument, e.g., pdfplumber.open("file.pdf", password =
"test").
The top-level pdfplumber.PDF class represents a single PDF and has two main properties:
Property Description
.metadata
A dictionary of metadata key/value pairs, drawn from the PDF's Info trailers. Typically includes
"CreationDate," "ModDate," "Producer," et cetera.
.pages A list containing one pdfplumber.Page instance per page loaded.
The pdfplumber.Page class is at the core of pdfplumber. Most things you'll do with pdfplumber will revolve around this class.
It has these main properties:
Property Description
.page_number The sequential page number, starting with 1 for the first page, 2 for the second, and so on.
.width The page's width.
.height The page's height.
.objects / .chars /
.lines / .rects
Each of these properties is a list, and each list contains one dictionary for each such object
embedded on the page. For more detail, see "Objects" below.
... and these main methods:
Method Description
Python library
Basic example
Loading a PDF
The pdfplumber.PDF class
The pdfplumber.Page class
4/21/2020 PDFPlumberPDFPython - Python | CTOLib
PDF generated with the free version of http://www.html2pdf.solutions
.crop(bounding_box) Returns a version of the page cropped to the bounding box, which should be
expressed as 4-tuple with the values (x0, top, x1, bottom). Cropped pages retain
objects that fall at least partly within the bounding box. If an object falls only partly
within the box, its dimensions are sliced to fit the bounding box.
.within_bbox(bounding_box) Similar to .crop, but only retains objects that fall entirely within the bounding box.
.filter(test_function)
Returns a version of the page with only the .objects for which test_function(obj)
returns True.
.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.
.extract_words(x_tolerance=0,
y_tolerance=0)
Returns a list of all word-looking things and their bounding boxes. Words are
considered to be sequences of characters where the difference between the x1 of
one character and the x0 of the next is less than or equal to x_tolerance and where
the doctop of one character and the doctop of the next is less than or equal to
y_tolerance.
.extract_tables(table_settings) Extracts tabular data from the page. For more details see "Extracting tables" below.
.to_image(**conversion_kwargs)
Returns an instance of the PageImage class. For more details, see "Visual debugging"
below. For conversion_kwargs, see here.
Each instance of pdfplumber.PDF and pdfplumber.Page provides access to four types of PDF objects. The following
properties each return a Python list of the matching objects:
.chars, each representing a single text character.
.annos, each representing a single annotation-text character.
.lines, each representing a single 1-dimensional line.
.rects, each representing a single 2-dimensional rectangle.
.curves, each representing a series of connected points.
Each object is represented as a simple Python dict, with the following properties:
Property Description
page_number Page number on which this character was found.
text E.g., "z", or "Z" or " ".
fontname Name of the character's font face.
size Font size.
adv Equal to text width * the font size * scaling factor.
upright Whether the character is upright.
height Height of the character.
width Width of the character.
x0 Distance of left side of character from left side of page.
x1 Distance of right side of character from left side of page.
Objects
char / anno properties
剩余12页未读,继续阅读
网迷
- 粉丝: 38
- 资源: 336
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- RTL8188FU-Linux-v5.7.4.2-36687.20200602.tar(20765).gz
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
- SPC统计方法基础知识.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1