Hi,
I am converting a Word document to pdf. the Document contains several word fields for example:
I want to display current date. so I use msword field like: {DATE \@ "dddd, MMMM d, yyyy"} , this will render as full date.
However looks like all the fields are always displayed as English (so the day name will be english like 'Sunday') instead of the language of the rest of the document (e.g. French, German ...)
Is there a way to control the language ?
Thank you
From the given
details, we have found that your requirement is to render the date and time in language (e.g. French, German,..) while converting Word document to PDF.
While performing Word to PDF conversion, Essential DocIO library renders the data and
time as per the culture used in your end.
We suggest you to set the French culture (fr-CA)
to display the date and time in French language or German culture (de-DE)
to display the date and time in German language as per your requirement.
Please refer the below highlighted code snippet to know the current culture
used in your end,
CultureInfo currentCulture = CultureInfo.CurrentCulture; |
Please refer the below highlighted code snippets to set the culture in your
end,
CultureInfo culture = new CultureInfo("fr-CA"); CultureInfo.DefaultThreadCurrentCulture = culture; CultureInfo.DefaultThreadCurrentUICulture = culture;
FileStream fileStream = new FileStream(@"Test-doc-french.docx", FileMode.Open, FileAccess.ReadWrite); //Loads the input document. WordDocument document = new WordDocument(fileStream, FormatType.Docx); //Convert Word document to PDF code snippet. |
Note: If this post is helpful, please consider accepting it as the solution
so that other members can locate it more quickly.
Thank you,
Is it possible to set the language without changing the Default thread culture ?
As my website code needs to generate documents in many languages, thus setting the default thread may cause issues when several threads try to create PDF with different languages
On further analyzing while
converting Word document to PDF in Microsoft Word application, there is no
option to set the language to display the date and time for the date field in
the Word document. So, it is necessary to set the culture in order to preserve
the date and time field in a specific language while converting Word document
to PDF using DocIO library.
To resolve the problem facing in changing the default thread culture, we
suggest you to pass the culture name which you want to preserve as a parameter to
the method (changed to the specific culture and convert Word document to PDF) and then reset the culture back to the default culture after PDF
conversion. So, the default culture is back now, which will not affect the other
document conversion. If you need, again set and reset culture for specific document
conversion.
We have prepared the sample application to change the specific culture back to
default culture after PDF conversion and it can be downloaded from the below
attachment.