Skip to content

Commit

Permalink
Add xml info to pdf metadata2 (#15)
Browse files Browse the repository at this point in the history
* Bump to 2.3.0

* PR #7 Include XML information in PDF metadata (cmcproject)

* update mustang validator

* fixes fx:DocumentFileName / fx:DocumentType order

* remove `schemas/ZUGFeRD2p2_extension_schema.xmp` (replaced by `xmp_schema.py` generator)

* removes date and seller from pdf metadata subject to simplify the code and remove hard coded English language

* removes doc type date and seller from pdf metadata subject (incl. the restriction to documents of type 380) to simplify the code and remove hard coded English language

* remove unused (now) unused constant INVOICE_TYPE_CODE and avoid the use of use bare `except`

* removes failing "Invalid doc type! XML value for TypeCode shall be 380 for an invoice." test

* allows to supply explicit profile level and extends profile auto detection to cover XRECHNUNG

* minor code style improvements like lazy % formatting in logging functions (logging-fstring-interpolation)

* fixes style (black)

* tests of auto detecting a XRechnung v2 and v3 profiles

* blacking again

* tests for en16931 auto profile recognition and auto profile recognition failure

* black again

* typo

* allow users to set custom pdf metadata and the PDF language identifier used by PDF readers for blind people

* black

* spelling

* Update drafthorse/pdf.py

* Run black

---------

Co-authored-by: Raphael Michel <[email protected]>
Co-authored-by: Raphael Michel <[email protected]>
  • Loading branch information
3 people authored Mar 10, 2024
1 parent 3171067 commit 7e0faa8
Show file tree
Hide file tree
Showing 10 changed files with 462 additions and 254 deletions.
8 changes: 5 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ further abstractions or simplifications. You can set and parse all parameters de
All output is validated against the official XSDs, but no validation of profile levels
(basic, comfort, extended) is performed.

The profile level is detected automatically based on the XML data and added to the PDF metadata.

Usage
-----

Expand Down Expand Up @@ -112,7 +114,7 @@ Generating::
# Note that the existing PDF should be compliant to PDF/A-3!
# You can validate this here: https://www.pdf-online.com/osa/validate.aspx
with open("input.pdf", "rb") as original_file:
new_pdf_bytes = attach_xml(original_file.read(), xml, 'EXTENDED')
new_pdf_bytes = attach_xml(original_file.read(), xml)

with open("output.pdf", "wb") as f:
f.write(new_pdf_bytes)
Expand All @@ -135,9 +137,9 @@ To validate files using mustang::

git clone https://github.com/ZUGFeRD/mustangproject.git
cd mustangproject
git checkout core-2.5.1
git checkout core-2.9.0
./mvnw clean package
java -jar Mustang-CLI/target/Mustang-CLI-2.5.1-SNAPSHOT.jar --action validate --source invoice.pdf
java -jar Mustang-CLI/target/Mustang-CLI-2.7.4-SNAPSHOT.jar --action validate --source invoice.pdf


Credits and License
Expand Down
2 changes: 1 addition & 1 deletion drafthorse/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "2.2.2"
version = "2.3.0"
7 changes: 4 additions & 3 deletions drafthorse/models/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class BaseElementMeta(type):
@classmethod
def __prepare__(self, name, bases):
del name, bases
return collections.OrderedDict()

def __new__(mcls, name, bases, attrs):
Expand Down Expand Up @@ -50,7 +51,7 @@ def _etree_node(self):

def to_etree(self):
node = self._etree_node()
for k, v in self._data.items():
for _, v in self._data.items():
if v is not None:
v.append_to(node)
return node
Expand Down Expand Up @@ -309,7 +310,7 @@ def from_etree(self, root):
self._text = root.text
try:
self._scheme_id = root.attrib["schemeID"]
except:
except Exception:
root.attrib["schemeID"] = ""
self._scheme_id = root.attrib["schemeID"]
self._set_on_input = True
Expand Down Expand Up @@ -386,7 +387,7 @@ def to_etree(self):
def from_etree(self, root):
try:
self._value = datetime.strptime(root.text, "%Y-%m-%dT%H:%M:%S").date()
except:
except Exception:
self._value = ""
self._set_on_input = True
return self
Expand Down
Loading

0 comments on commit 7e0faa8

Please sign in to comment.