从libreoffice calc导出发票和收据到pdf文件的工具
invrcptexporter的Python项目详细描述
将libreoffice calc的发票和收据导出为pdf文件的工具
必须使用选项--system-site-packagesas创建virtualenv 它需要使用由 $ sudo apt-get install python3-uno,在ubuntu上。(不幸的是,UNO PIP没有提供模块。)
代码基于christopher5106的教程(非常感谢他):
('http://christopher5106.github.io/office/2015/12/06/openoffice-','libreoffice-automate-your-office-tasks-with-python-macros.html')
工作原理
- 我们用打开的套接字打开libreoffice
- 我们使用python通过套接字向libreoffice发送命令(您 应该使用iptables来阻止指定tcp上的传入连接 出于安全原因的端口)
要在套接字打开的情况下打开libreoffice,请使用下面的命令行:
libreoffice \ --accept="socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"
安装以进行测试
在ubuntu 14.04上
将python3 uno作为系统范围的软件包安装,因为此软件包不是 可通过PIP获得:
$ sudo apt-get install python3-uno
创建virtualenv(可能,使用virtualenvwrapper) --system-site-pacakges:
$ mkvirtualenv --system-site-packages invrcptexporter
从pip安装所需的软件包:
$ pip install -rrequirements-test.txt
从apt安装poppler utils,因为我们必须在 测试:
$ sudo apt-get install poppler-utils
我尝试了其他一些选择,例如 Pypdf2,在许多情况下不起作用
配置~/.invrcptexporterrc:
$ cd ~ $ cp /your/project/path/source/invrcptexporterrc .invrcptexporterrc
在这个rc文件中调整设置,最重要的是 script_path是“source”目录的绝对路径
运行测试:
$ /your/project/path/source/test.sh
注意:test.sh是一个黑客(您可以从内部的注释中看到详细信息 每次运行时,都必须手动关闭(退出或 ctrl+q)打开的libreoffice ui,这样测试将继续 运行
为用户安装
将python3 uno作为系统范围的软件包安装,因为此软件包不是 可通过PIP获得:
$ sudo apt-get install python3-uno
从pip安装invrcptexporter:
$ pip3 install invrcptexporter
使用/sample_invoice_list.ods作为模板
程序当前仅作为库提供,请参见示例 使用代码: /source/sample-code/invrcptexporter/