easy operate OFD
Project description
easyofd
关于这个库:
鉴于目前python解析ofd没有啥好用的库所以决定自己整一个。
已实现功能 :
1 解析ofd
2 ofd转pdf
3 ofd转图片
关于 jb2格式图片解析 使用了第三方库 jbig2dec 去读取jb2格式图片 参考下面链接安装使用jbig2dec https://github.com/rillian/jbig2dec
:hand:实现参考文档
项目链接: https://github.com/renoyuan/easyofd
安装
pip install easyofd
ofd2pdf demo
#!/usr/bin/env python
#-*- coding: utf-8 -*-
#PROJECT_NAME: F:\code\easyofd\test
#CREATE_TIME: 2023-10-18
#E_MAIL: renoyuan@foxmail.com
#AUTHOR: reno
#note: use demo
import sys
import os
project_dir = os.path.join(os.path.dirname(os.getcwd()),"easyofd")
pkg_dir = os.path.dirname(os.getcwd())
sys.path.insert(0,project_dir)
sys.path.insert(0,pkg_dir)
import base64
from PIL import Image
import numpy as np
from easyofd.ofd import OFD
if __name__ == "__main__":
with open(r"增值税电子专票5.ofd","rb") as f:
ofdb64 = str(base64.b64encode(f.read()),"utf-8")
ofd = OFD()
ofd.read(ofdb64) # 读取ofd
# print(ofd.data)
pdf_bytes = ofd.to_pdf() # 转pdf
img_np = ofd.to_jpg() # 转图片
ofd.del_data()
with open(r"test.pdf","wb") as f:
f.write(pdf_bytes)
for idx, img in enumerate(img_np):
im = Image.fromarray(img)
im.save(f"test_img{idx}.jpg")
ps:
1 本库尚不完善使用需要谨慎,欢迎提各种Issue.
2 目前ofd 文件使用尚未普及,作者接触的文件也不多,遇到无法解析的文件,可以发我邮箱(renoyuan@foxmail.com),有时间会去优化版本.
版本规划:
1.0 计划重点在ofd 解析模块的完善 及ofd文档格式的转换 ofd2pdf ofd2img 等
2.0 计划完成ofdd文件绘制 以及其他文档转ofd pdf2ofd txt2ofd 等
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
easyofd-0.0.10.2.tar.gz
(30.9 kB
view hashes)
Built Distribution
easyofd-0.0.10.2-py3-none-any.whl
(35.5 kB
view hashes)
Close
Hashes for easyofd-0.0.10.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1464144fa7829d90633a67c4959c44b95379404d3b9b4f9fa24b6898dccb61a9 |
|
MD5 | 1fb78f847cf4d92ef5972adf1d394c62 |
|
BLAKE2b-256 | 013ec497583a28d0fdcda115062ea1fd873c17193d2e49d36848b5614b59fc55 |