Skip to content

Commit

Permalink
more configureable document properties (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
SourceDoctor authored Nov 19, 2024
1 parent 037084d commit 5c45ef0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions drafthorse/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ def attach_xml(original_pdf, xml_data, level=None, metadata=None, lang=None):
If omitted, autodetection is performed
:type level: string
:param metadata: optional dict with user defined PDF metadata
for fields "author", "keywords", "title" and "subject". If metadata is None (default value),
for fields "author", "keywords", "title", "subject", "creator" and "producer". If metadata is None (default value),
this lib will generate some metadata by extracting relevant info from the Factur-X/Order-X XML.
Here is an example for the metadata argument:
```
pdf_metadata = {
'author': 'MyCompany',
'keywords': 'Factur-X, Invoice',
'title': 'MyCompany: Invoice I1242',
'creator': 'My Company Application',
'producer': 'My company Accountant',
'subject':
'Factur-X invoice I1242 dated 2017-08-17 issued by MyCompany',
}
Expand Down Expand Up @@ -137,7 +139,7 @@ def _prepare_pdf_metadata_txt(pdf_metadata):
return {
"/Author": pdf_metadata.get("author", ""),
"/CreationDate": pdf_date,
"/Creator": "python-drafthorse",
"/Creator": pdf_metadata.get("creator", "python-drafthorse"),
"/Keywords": pdf_metadata.get("keywords", ""),
"/ModDate": pdf_date,
"/Subject": pdf_metadata.get("subject", ""),
Expand All @@ -156,8 +158,8 @@ def _prepare_xmp_metadata(profile, pdf_metadata):
title=pdf_metadata.get("title", ""),
author=pdf_metadata.get("author", ""),
subject=pdf_metadata.get("subject", ""),
producer="pypdf",
creator_tool="python-drafthorse",
producer=pdf_metadata.get("producer", "pypdf"),
creator_tool=pdf_metadata.get("creator", "python-drafthorse"),
timestamp=datetime.now(tz=timezone.utc).strftime("%Y-%m-%dT%H:%M:%S+00:00"),
urn="urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#",
documenttype="INVOICE",
Expand Down Expand Up @@ -321,6 +323,8 @@ def _extract_xml_info(xml_data, level=None, metadata=None):
"keywords": metadata.get("keywords", "Factur-X"),
"title": metadata.get("title", number),
"subject": metadata.get("subject", number),
"producer": metadata.get("producer", "pypdf"),
"creator": metadata.get("creator", "python-drafthorse"),
}

# get profile
Expand Down

0 comments on commit 5c45ef0

Please sign in to comment.