Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Adding support for reading .metadata.keywords #2939

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading