Skip to content

Commit

Permalink
ENH: Adding support for reading .metadata.keywords (#2939)
Browse files Browse the repository at this point in the history
Co-authored-by: Cimon Lucas (LCM) <[email protected]>
  • Loading branch information
Lucas-C and Cimon Lucas (LCM) authored Nov 12, 2024
1 parent 7094bce commit 545a79c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pypdf/_doc_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,21 @@ def modification_date_raw(self) -> Optional[str]:
"""
return self.get(DI.MOD_DATE)

@property
def keywords(self) -> Optional[str]:
"""
Read-only property accessing the document's keywords.
Returns a ``TextStringObject`` or ``None`` if keywords are not
specified.
"""
return self._get_text(DI.KEYWORDS)

@property
def keywords_raw(self) -> Optional[str]:
"""The "raw" version of keywords; can return a ``ByteStringObject``."""
return self.get(DI.KEYWORDS)


class PdfDocCommon:
"""
Expand Down
2 changes: 2 additions & 0 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ def test_read_metadata(pdf_path, expected):
docinfo.creation_date_raw
docinfo.modification_date
docinfo.modification_date_raw
docinfo.keywords
docinfo.keywords_raw
if "/Title" in metadict:
assert isinstance(docinfo.title, str)
assert metadict["/Title"] == docinfo.title
Expand Down

0 comments on commit 545a79c

Please sign in to comment.