0
点赞
收藏
分享

微信扫一扫

python提取pdf文档中的表格数据、svg格式转换为pdf

提取pdf文件中的表格数据原文链接

​​https://www.analyticsvidhya.com/blog/2020/08/how-to-extract-tabular-data-from-pdf-document-using-camelot-in-python/​​

另外参考

​​https://camelot-py.readthedocs.io/en/master/​​

使用camelot模块

可以直接使用pip进行安装

pip install "camelot-py[cv]"

用到的pdf示例文件

​​​http://gstcouncil.gov.in/sites/default/files/gst-revenue-collection-march2020.pdf​​

读入pdf文件

import camelot
tables = camelot.read_pdf('gst-revenue-collection-march2020.pdf', flavor='stream', pages='0-3')

这里​​flavor​​参数的作用暂时还不知道

如果表格跨页需要指定pages参数

tables
tables[2]
tables[2].df

tables可以返回解析获得的表格数量

tables[2]获取指定的表格

tables[2].df将表格数据转换成数据框

pandas 行合并

aa = {"A":[1,2,3],"B":[4,5,6]}
bb = {"A":[4],"B":[7]}
import pandas as pd
a = pd.DataFrame(aa)
b = pd.DataFrame(bb)
a.append(b)

SVG格式转换为pdf格式原文链接

​​​https://www.tutorialexample.com/a-simple-guide-to-python-convert-svg-to-pdf-with-svglib-python-tutorial/​​

使用到的是svglib这个库,直接使用pip安装

pip install svglib

svg转换为pdf格式代码

from svglib.svglib import svg2rlg
from reportlab.graphics import renderPDF
drawing = svg2rlg("home.svg")
renderPDF.drawToFile(drawing, "file.pdf")

欢迎大家关注我的公众号

小明的数据分析笔记本

举报

相关推荐

0 条评论