ModDate date issues

Issue #1: Cannot set Document.Info.ModDate to UTC date. Aspose.PDF requires a DateTime value with Local kind.

_pdf.Info.ModDate = DateTime.UtcNow;

It should be allowed to set ModDate to UTC date. The corresponding value in PDF should be: /ModDate(D:yyyyMMddHHmmss+00'00') or /ModDate(D:yyyyMMddHHmmssZ).

Ideally, Document.Info.ModDate should be of the DateTimeOffset type.

Issue #2: Aspose.Pdf returns incorrect value while reading Document.Info.ModDate property.

Let’s assume the PDF has /ModDate(D:200101010101+03'00') (2001-01-01 01:01:01 +3:00).

Document.Info.ModDate returns {01/01/2001 01:01:01} with Kind equal to Unspecified. DateTime does not have timezone offset information. It means we lost the real modification date.

Expected: As ModDate is of DateTime type, Aspose.Pdf should:

  • read the value from PDF (date, time, time zone)
  • convert date time to UTC or Local taking into consideration both local time zone offset and ModDate time zone offset.

Thanks,
Oleksii

For internal reference: CLN-2882

@oleksii88

Hi Oleksii,

Thank you for bringing up these issues regarding the Document.Info.ModDate property in Aspose.PDF. Let’s address each of your concerns:

Issue #1: The ModDate property currently requires a DateTime value with a local kind. Setting it directly to a UTC date like DateTime.UtcNow is not supported. To work around this, you can convert your UTC date to local time before assigning it to ModDate. Here’s a code snippet to illustrate this:

DateTime utcDate = DateTime.UtcNow;
DateTime localDate = utcDate.ToLocalTime();
_pdf.Info.ModDate = localDate;

Issue #2: When reading the ModDate property, it returns a DateTime object without timezone information, which can lead to the loss of the original modification date. To handle this correctly, you will need to parse the original date string from the PDF and account for the timezone offset. The current implementation does not automatically convert the date to UTC or local time considering both offsets.

Solution: For your expected behavior, you will need to implement a custom solution that extracts the date string from the PDF, parses it, and adjusts it according to the specified timezone offset.

Next Steps: If you would like, I can assist you further with the implementation details or provide additional examples. Please let me know how you would like to proceed.

Best regards!

Issue #1: To work around this, you can convert your UTC date to local time

Unfortunately, we are required to set the ModDate in UTC. Would it be possible to register an enhancement request to change the ModDate property type to DateTimeOffset?

I understand that this is a free support forum and such a request may remain in the backlog for some time. However, having it tracked as a potential improvement would still be appreciated, even if it’s addressed at a later stage.

Issue #2: handle this correctly, you will need to parse the original date string from the PDF and account for the timezone offset.

Yes, Aspose.Pdf allows reading the ModDate as a string via Info["ModDate"]. I reported this issue with the intention of helping improve the product.

Using the DateTimeOffset type instead of DateTime would also address this limitation by properly preserving and handling the timezone offset.

Thanks,
Oleksii

@oleksii88

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-60375

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.