Skip to content

Commit 529afdc

Browse files
committed
Allow deleting pdf metadata keys
And document the standard keys in PdfPages. Also insert the matplotlib version in the default value of Producer as well as Creator, to retain a debugging clue in case the user overrides one of them.
1 parent 1fa4dd7 commit 529afdc

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/matplotlib/backends/backend_pdf.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,6 @@ def __init__(self, filename, metadata=None):
472472
'Pages': self.pagesObject}
473473
self.writeObject(self.rootObject, root)
474474

475-
revision = ''
476475
# get source date from SOURCE_DATE_EPOCH, if set
477476
# See https://reproducible-builds.org/specs/source-date-epoch/
478477
source_date_epoch = os.getenv("SOURCE_DATE_EPOCH")
@@ -484,11 +483,13 @@ def __init__(self, filename, metadata=None):
484483

485484
self.infoDict = {
486485
'Creator': 'matplotlib %s, http://matplotlib.org' % __version__,
487-
'Producer': 'matplotlib pdf backend%s' % revision,
486+
'Producer': 'matplotlib pdf backend %s' % __version__,
488487
'CreationDate': source_date
489488
}
490489
if metadata is not None:
491490
self.infoDict.update(metadata)
491+
self.infoDict = {k: v for (k, v) in self.infoDict.items()
492+
if v is not None}
492493

493494
self.fontNames = {} # maps filenames to internal font names
494495
self.nextFont = 1 # next free internal font name
@@ -2459,6 +2460,13 @@ def __init__(self, filename, keep_empty=True, metadata=None):
24592460
'Document Information Dictionary'), e.g.:
24602461
`{'Creator': 'My software', 'Author': 'Me',
24612462
'Title': 'Awesome fig'}`
2463+
2464+
The standard keys are `'Title'`, `'Author'`, `'Subject'`,
2465+
`'Keywords'`, `'Creator'`, `'Producer'`, `'CreationDate'`,
2466+
`'ModDate'`, and `'Trapped'`. Values have been predefined
2467+
for `'Creator'`, `'Producer'` and `'CreationDate'`. They
2468+
can be removed by setting them to `None`.
2469+
24622470
"""
24632471
self._file = PdfFile(filename, metadata=metadata)
24642472
self.keep_empty = keep_empty

0 commit comments

Comments
 (0)