Skip to content

correct datetime format in XMP Metadata for CreateDate/ModifyDate #166

@flensrocker

Description

@flensrocker

I'm looking into getting PDFsharp generate PDF/A compliant documents (my goal is PDF/A-3, but since PDF/A-1A is already included I start there).

I ran PdfATests.Simple_PDF_A_document and uploaded the file here: https://www.pdfforge.org/online/en/validate-pdfa

Result:

ISO 19005-1:2005, 6.7.3
If a document information dictionary does appear at a document, then all of its entries that have analogous properties in predefined XMP schemas, shall also be embedded in the file in XMP form with equivalent values.

Running the document through one of the many online converter tools and looking at the differences, one outstanding difference is the format of the CreateDate and ModifyDate entries in the XMP metadata.

Wrong:

<xmp:CreateDate>2024-09-04T10:34:16.0000000</xmp:CreateDate>

Right:

<xmp:CreateDate>2024-09-04T10:34:16+02:00</xmp:CreateDate>

So instead of using the format string "o" the following should be used: "yyyy-MM-ddTHH:mm:ssK"

But this doesn't work, if the provided DateTime object doesn't specify a DateTimeKind. So setting DateTimeKind.Local if DateTimeKind.Unspecified resolves this problem (it doesn't really matter if it's Local or Utc, because none knows the original kind - but when creating the document from scratch with the test it matches local time).

I will provide a PR with this minimal changes, after that the validator doesn't complain anymore.

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