We're sorry GroupDocs doesn't work properply without JavaScript enabled.

Free Support Forum - groupdocs.com

Error using CustomFont directory when converting docx to pdf on linux server

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?

@lekha.menon

Please share following details and we’ll look into this issue:

  • A short video explaining the steps to reproduce the issue on your server
  • Problematic DOCX file
  • Server details (name, version etc)

Docx file:
3737_W062_Advise Rehab is Exhausted_11-3665.docx (39.5 KB)

Pdf file generated using the using GroupDocs.Conversion for .Net ver 22.5.0:
3737_W062_Advise Rehab is Exhausted_11-3665.pdf (49.0 KB)

On click of download button, the program reads the docx file from an FTP site and passes the byte array to the above program.

The server name and version: Red Hat Enterprise Linux release 8.5 (Ootpa)

@lekha.menon

We are investigating this scenario. Your investigation ticket ID is CONVERSIONNET-5313. We’ll notify you as there’s any progress update.