Skip to content

macOS Preview App Displays Incorrect Date/Time due to Timezone Formatting #73

@appare45

Description

@appare45

I've encountered a rendering issue where the macOS Preview app seems to ignore the timezone offset specified in the CreationDate and ModDate fields.

This appears to be a compatibility issue with Preview, as other viewers like Adobe Reader display the date and time correctly.

Environment

  • pdf-writer: 0.14.0
  • macOS: Sequoia 15.6.1
  • Preview.app: Version 11.0 (1069.7.1)

Steps to Reproduce

  1. Generate a PDF file with a specific date and UTC offset. My system's timezone is JST (+09:00).

    let date = Date::new(2025)
            .month(10)
            .day(13)
            .hour(17)
            .minute(0)
            .second(0)
            .utc_offset_hour(9);
    pdf.document_info(document_info_id)
        .modified_date(date)
        .creation_date(date);
  2. Open the resulting PDF file with the macOS Preview app.

Observed Behavior

Preview displays the time as 02:00, seemingly ignoring the +09:00 offset and falling back to UTC.

Image

Expected Behavior

The time should be displayed as 17:00, correctly reflecting the provided timezone offset. For comparison, Adobe Reader renders it correctly.

Image

Proposed Solution

After inspecting the raw PDF output, I found that adding a trailing apostrophe (') to the date string's timezone offset resolves the issue in Preview.

Before (Current pdf-writer Output):

$ strings target/before.pdf | grep Date
  /ModDate (D:20251013170000+09'00)
  /CreationDate (D:20251013170000+09'00)

After (With Proposed Fix):

$ strings target/after.pdf | grep Date
  /ModDate (D:20251013170000+09'00')
  /CreationDate (D:20251013170000+09'00')

This format with the trailing apostrophe appears to be a common practice for ensuring compatibility. For instance, a PDF generated by Microsoft Word uses the same format for its date strings, as shown below:

$ strings MS_WORD.pdf | grep "/CreationDate"
/Creator(Microsoft Word) /CreationDate(D:20251013090356+00'00') /ModDate(D:20251013090356+00'00')

Applying the following diff to pdf-writer would align it with this practice and fix the parsing issue in macOS Preview.

diff --git a/src/object.rs b/src/object.rs
index 99e8ca6..bdfa338 100644
--- a/src/object.rs
+++ b/src/object.rs
@@ -557,7 +557,7 @@ impl Primitive for Date {
                 } else {
                         write!(
                                 buf.inner,
-                                "{:+03}'{:02}",
+                                "{:+03}'{:02}'",
                                 utc_offset_hour, self.utc_offset_minute
                         )
                         .unwrap();

Would you consider applying this change to improve compatibility with the macOS Preview app?

If you do not plan to address this, please feel free to close this issue. Thank you for your consideration!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions