我正在使用python 3.8和Alexis de Lattre的库:https://github.com/akretion/factur-x
正如您在他的回购协议上看到的,它用于从常规PDF发票和符合Factur-X的XML文件生成Factur-X发票
我非常友好地使用了提供的命令行工具:
通过我的内部公司提供的一个虚拟示例(第一个附件)成功:
2020-09-15 17:06:11,867 [INFO] A valid XML file factur-x.xml has been found in the PDF file
FutureWarning: The behavior of this method will change in future versions. Use specific 'len(elem)' or 'elem is not None' test instead. [facturx.py:92]
2020-09-15 17:06:11,868 [INFO] Factur-X flavor is factur-x (autodetected)
2020-09-15 17:06:11,868 [INFO] Factur-X level is basic (autodetected)
2020-09-15 17:06:11,889 [INFO] Factur-X XML file successfully validated against XSD
2020-09-15 17:06:11,890 [INFO] Returning an XML file factur-x.xml
2020-09-15 17:06:11,891 [INFO] File Facture_DOM_BASIC_5_facturx.xml generated
但这个输入示例似乎从一开始就与facturx兼容,实际上是一个示例输出。。。因此,我使用了我自己的PDF发票在线制作(例如,在https://app.invoicesimple.com/,第二个附件中),或者使用Word+export制作。这一次,在使用相同的命令行工具时,出现了与目录相关的错误:
2020-09-15 17:05:36,992 [INFO] No Names entry in Catalog
Traceback (most recent call last):
File "facturx-pdfextractxml.py", line 95, in <module>
main(options, arguments)
File "facturx-pdfextractxml.py", line 80, in main
logger.warn('File %s has not been created', out_xml_filename)
File "C:\Users\Selim SEDIKKI\AppData\Local\Programs\Python\Python38\lib\logging\__init__.py", line 1449, in warn
warnings.warn("The 'warn' method is deprecated, "
File "C:\Users\Selim SEDIKKI\AppData\Local\Programs\Python\Python38\lib\warnings.py", line 109, in _showwarnmsg
sw(msg.message, msg.category, msg.filename, msg.lineno,
File "C:\Users\Selim SEDIKKI\AppData\Local\Programs\Python\Python38\lib\site-packages\PyPDF4\pdf.py", line 1133, in _showwarning
file.write(formatWarning(message, category, filename, lineno, line))
File "C:\Users\Selim SEDIKKI\AppData\Local\Programs\Python\Python38\lib\site-packages\PyPDF4\utils.py", line 69, in formatWarning
file = filename.replace("/", "\\").rsplit("\\", 1)[1] # find the file name
IndexError: list index out of range
我在python脚本中搜索了一些见解(主脚本和facturx.py模块),并在web上进行了搜索,但我有点被卡住了。。而且我的最后期限很短,所以我不能自己再浪费一个下午;)
另一个附属问题是关于脚本facturx-pdfgen.py[input pdf_file_name][input facturx_xml_file_name][output facturx-compliant_pdf_file_name]。既然我们使用facturx-pdfextractxml.py生成facturx_xml_文件,而且该xml必须包含pdf中的所有信息,为什么我们还需要使用facturx-pdfgen.py的原始pdf文件?而不是从仅xml输入开始生成最终符合Factur-X的PDF文件
感谢所有比我理解得更好的人;)
我意识到facturx-pdfextractxml.py实际上是在提取输入pdf中附加的先前存在的xml。因此,我们必须解析pdf中包含的信息,并在futurx biblio之外创建符合Factur-X的XML文件(包含所有必需的信息和适当的结构)
我找到了另一本书pdfminer来解析pdf,它实际上可以生成xml格式
现在的问题是:一旦我映射了2XML(从pdfminer输入,输出到Factur-X兼容文件),它对新的发票pdf是否会很健壮?换句话说,发票pdf结构是否足够规则
我想我得试试。如果您已有一些见解,请分享;)
相关问题 更多 >
编程相关推荐