invoice-x / factur-x-ng

Python lib for Factur-X, the e-invoicing standard for France and Germany
Other
34 stars 8 forks source link

Error with PyPDF2 #16

Closed duskybomb closed 6 years ago

duskybomb commented 6 years ago

If there is no embedded xml to pdf:

Traceback (most recent call last):
  File "my_file.py", line 4, in <module>
    factx = FacturX('oyo.pdf')
  File "D:\GSoC\factur-x\facturx\facturx.py", line 57, in __init__
    xml = self._xml_from_file(pdf_file)
  File "D:\GSoC\factur-x\facturx\facturx.py", line 80, in _xml_from_file
    if '/EmbeddedFiles' not in pdf_root['/Names']:
  File "D:\Projects\Invoice2data-GUI\venv\lib\site-packages\PyPDF2\generic.py", line 516, in __get
item__
    return dict.__getitem__(self, key).getObject()
KeyError: '/Names'

Works fine with pdf having embedded xml

m3nu commented 6 years ago

It needs an extra IF to check for the presence of metadata. This is not related to embedded XML. Could also be an image or a font. Small fix.

duskybomb commented 6 years ago

Isn't this line checking the presence of metadata? if '/EmbeddedFiles' not in pdf_root['/Names']:

m3nu commented 6 years ago

Yes. That's checking for embedded files. It may fail if nothing is embedded.

Embedding is not only for our XML file. It's also for fonts, images, certificates, etc.

duskybomb commented 6 years ago

Sorry, I didn't see you assigned it to yourself.

m3nu commented 6 years ago

No worries. Good you solved it.