azw3转换为pdf_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/

实现提取pdf文档中的表格数据需要使用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 中两个数据框按照行合并需要用到append()方法

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")

欢迎大家关注我的公众号

小明的数据分析笔记本e3e13c6a016cb003c4c170cfe8656f00.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值