赞
踩
OFD 格式简单来说是PDF的国产替代。目前只有国内一定范围内在用,所以相对应的工具库还比较少。
pip 安装
pip install easyofd
github 源码地址
git clone https://github.com/renoyuan/easyofd.git
import base64 import json from PIL import Image from easyofd.ofd import OFD with open(r"增值税电子专票5.ofd","rb") as f: ofdb64 = str(base64.b64encode(f.read()),"utf-8") ofd = OFD() # 初始化OFD 工具类 ofd.read(ofdb64,save_xml=False, xml_name="testxml") # 读取ofdb64 # print(ofd.data) # ofd.data 为程序解析结果 pdf_bytes = ofd.to_pdf() # 转pdf ofd.del_data() with open(r"增值税电子专票5.pdf","wb") as f: f.write(pdf_bytes)
import base64 import json from PIL import Image from easyofd.ofd import OFD with open(r"增值税电子专票5.ofd","rb") as f: ofdb64 = str(base64.b64encode(f.read()),"utf-8") ofd = OFD() # 初始化OFD 工具类 ofd.read(ofdb64,save_xml=False, xml_name="testxml") # 读取ofdb64 # print(ofd.data) # ofd.data 为程序解析结果 img_np = ofd.to_jpg() # 转图片 ofd.del_data() for idx, img in enumerate(img_np): im = Image.fromarray(img) im.save(f"test_img{idx}.jpg")
easyofd 有一个windows客户端 程序可以不需要代码直接使用
下载地址:https://github.com/renoyuan/easyofd/releases
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。