We use the following code snippet to convert from docx to pdf using GroupDocs.Conversion for .Net ver 22.5.0:
private static LoadOptions LoadOptionsForWordDoc => new WordProcessingLoadOptions {EmbedTrueTypeFonts=true};
private static ConverterSettings ConverterSettings => new ConverterSettings(){ FontDirectories = new List<string>(){ Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CustomFonts/")}};
public async Task<byte[]> ConvertToPdf(string filename, byte[] docxFile, bool applyCommsFormatting = true)
{
try
{
var pdfConvertOptions = new PdfConvertOptions();
var converter = applyCommsFormatting ?
new Converter(() => new MemoryStream(docxFile), () => LoadOptionsForWordDoc, () => ConverterSettings) :
new Converter(() => new MemoryStream(docxFile), () => ConverterSettings);
var pdfStream = new MemoryStream();
converter.Convert(() => pdfStream, pdfConvertOptions);
return pdfStream.ToArray();
}
catch (Exception ex)
{
_logger.Error(ex.ToString());
}
return null;
}
The code works well on my local windows machine but on our linux server throws the following error:
GroupDocs.Conversion.Exceptions.GroupDocsConversionException: The type initializer for ‘  ’ threw an exception.
at d.()
at GroupDocs.Conversion.Converter.()
at Core.Services.DocumentService.ConvertToPdf(String filename, Byte[] docxFile, Boolean applyCommsFormatting)
I checked the file path to custom fonts and can see the font folder in server. Could you please check and let us know what is causing the exception?