File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed
Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 3131import re
3232import struct
3333import zlib
34+ from datetime import datetime
3435from io import BytesIO
3536from pathlib import Path
3637from typing import (
@@ -230,6 +231,48 @@ def producer_raw(self) -> Optional[str]:
230231 """The "raw" version of producer; can return a ``ByteStringObject``."""
231232 return self .get (DI .PRODUCER )
232233
234+ @property
235+ def creation_date (self ) -> Optional [datetime ]:
236+ """
237+ Read-only property accessing the document's **creation date**.
238+ """
239+ text = self ._get_text (DI .CREATION_DATE )
240+ if text is None :
241+ return None
242+ return datetime .strptime (text .replace ("'" , "" ), "D:%Y%m%d%H%M%S%z" )
243+
244+ @property
245+ def creation_date_raw (self ) -> Optional [str ]:
246+ """
247+ The "raw" version of creation date; can return a ``ByteStringObject``.
248+
249+ Typically in the format D:YYYYMMDDhhmmss[+-]hh'mm where the suffix is the
250+ offset from UTC.
251+ """
252+ return self .get (DI .CREATION_DATE )
253+
254+ @property
255+ def modification_date (self ) -> Optional [datetime ]:
256+ """
257+ Read-only property accessing the document's **modification date**.
258+
259+ The date and time the document was most recently modified.
260+ """
261+ text = self ._get_text (DI .MOD_DATE )
262+ if text is None :
263+ return None
264+ return datetime .strptime (text .replace ("'" , "" ), "D:%Y%m%d%H%M%S%z" )
265+
266+ @property
267+ def modification_date_raw (self ) -> Optional [str ]:
268+ """
269+ The "raw" version of modification date; can return a ``ByteStringObject``.
270+
271+ Typically in the format D:YYYYMMDDhhmmss[+-]hh'mm where the suffix is the
272+ offset from UTC.
273+ """
274+ return self .get (DI .MOD_DATE )
275+
233276
234277class PdfReader :
235278 """
Original file line number Diff line number Diff line change @@ -95,6 +95,10 @@ def test_read_metadata(pdf_path, expected):
9595 docinfo .producer_raw
9696 docinfo .subject
9797 docinfo .subject_raw
98+ docinfo .creation_date
99+ docinfo .creation_date_raw
100+ docinfo .modification_date
101+ docinfo .modification_date_raw
98102 if "/Title" in metadict :
99103 assert metadict ["/Title" ] == docinfo .title
100104
You can’t perform that action at this time.
0 commit comments