Free Support Forum - aspose.com

Time zone issue with date field on converting DOC to PDF

Hi Support
I am facing an issue with date fields on converting a word document to PDF using Aspose.Words version # 18.1. When the machine on which the word document is generated and the machine on which the word document is converted to PDF have different time zones then upon converting the behavior with date is (T - 1). For Example if the date set in word document is 27-08-2017 then after converting it to PDF it becomes 26-08-2017.
It looks like machine time zone specific issue.
Your reply will be highly appreciated.
Following is the code snippet:

Aspose.Words.Document Document = new Aspose.Words.Document(InputFileName);
Aspose.Words.Saving.PdfSaveOptions PdfSaveOptions = new Aspose.Words.Saving.PdfSaveOptions();
PdfSaveOptions.Compliance = Aspose.Words.Saving.PdfCompliance.PdfA1b;
PdfSaveOptions.UpdateLastSavedTimeProperty = true;

            using (var CompressedFileStream = new FileStream(tempfile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
            {
                Document.Save(CompressedFileStream, PdfSaveOptions);
                CompressedFileStream.Seek(0, System.IO.SeekOrigin.Begin);
                OutputFileBytes = new byte[CompressedFileStream.Length];
                CompressedFileStream.Read(OutputFileBytes, 0, (int)CompressedFileStream.Length);
            }

@Muddassir_Awan,

Thanks for your inquiry. In your case, we suggest you please set the value of FieldOptions.FieldUpdateCultureSource property as FieldUpdateCultureSource.FieldCode. By default, the culture of the current thread is used. Please check the following code snippet. Hope this helps you.

// Set the culture used during field update to the culture used by the field.
doc.FieldOptions.FieldUpdateCultureSource = FieldUpdateCultureSource.FieldCode;
doc.MailMerge.Execute(new String[] { "Date2" }, new object[] { new DateTime(2018, 1, 01) });

@tahir.manzoor
I have added the provided code snippet in my code and check the issue again. Issue still exists. Kindly check the following updated code snippet:

Aspose.Words.Document Document = new Aspose.Words.Document(InputFileName);
Aspose.Words.Saving.PdfSaveOptions PdfSaveOptions = new Aspose.Words.Saving.PdfSaveOptions();
PdfSaveOptions.Compliance = Aspose.Words.Saving.PdfCompliance.PdfA1b;
Document.FieldOptions.FieldUpdateCultureSource = Aspose.Words.Fields.FieldUpdateCultureSource.FieldCode;

            using (var CompressedFileStream = new FileStream(tempfile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
            {
                Document.Save(CompressedFileStream, PdfSaveOptions);
                CompressedFileStream.Seek(0, System.IO.SeekOrigin.Begin);
                OutputFileBytes = new byte[CompressedFileStream.Length];
                CompressedFileStream.Read(OutputFileBytes, 0, (int)CompressedFileStream.Length);
            }

@Muddassir_Awan,

Thanks for your inquiry. Please ZIP and attach your input Word document here for testing. We will investigate the issue on our side and provide you more information.

Please find the attached document. On changing the date fields data on a machine with different time zone and then converting the document to PDF format causes the issue. As mentioned above in the chat.
138-doc uploading issue.zip (57.5 KB)

@Muddassir_Awan,

Thanks for sharing the detail. In your document, you are using content controls. So, you do not need to use Document.FieldOptions property. We have converted the document to PDF using latest version of Aspose.Words for .NET 18.8 and have not found the shared issue. Please use Aspose.Words for .NET 18.8.

If you still face the problem, please share the time zones on which you are converting this document to PDF. Please also share the PDF files that show the undesired behavior. We will investigate this issue further and provide you more information.

I have tried the above mentioned issue with Aspose.Words for .Net 18.8. But still the issue is not resolved. When converting the word document into PDF on the machine with different time zone the issue still occurs.
Kindly find the attached documents

Issue docs.zip (107.1 KB)

@Muddassir_Awan,

Thanks for sharing the detail. The shared PDF file is generated by Aspose.Words 18.1. Please try Aspose.Words for .NET 18.8.

Please note that Aspose.Words mimics the behavior of MS Word. Please save your document to PDF at different time zones and check the output. If you get the same output, this is not a bug in Aspose.Words.

If you still face the problem after using Aspose.Words for .NET 18.8, please share the time zones on which you are converting this document to PDF. Please also share the PDF files that show the undesired behavior. Thanks for your cooperation.