Issue with converting pdf to .docx on Linux machines using ASPOSE.NET

We are having trouble converting a pdf file to docx using ASPOSE. This works on Windows but not on Linux machines. Here is the code snippet we are using. This happens with any pdf file. Any guidance on why this may be happening would be much appreciated!

Code snippet:

using System;
using System.IO;
using Aspose.Pdf;

namespace ConvertToDocx
{
class Program
{
static void Main(string[] args)
{
// ExStart:ConvertToDOCX
// The path to the documents directory.
var dataDir = GetDataDir_AsposePdf_DocumentConversion();

        // Open the source PDF document
        var pdfDocument = new Document(dataDir + "cerfa_14076-02 COURT SEJOUR.pdf");

        // Instantiate DocSaveOptions object
        var saveOptions = new DocSaveOptions {Format = DocSaveOptions.DocFormat.DocX};
        // Specify the output format as DOCX
        // Save document in docx format
        pdfDocument.Save("ConvertToDOCX_out.docx", saveOptions);
        // ExEnd:ConvertToDOCX
    }
    
    private static String GetDataDir_AsposePdf_DocumentConversion()
    {
        return Path.GetFullPath(GetDataDir_Data() + "/DocumentConversion/");
    }

    private static string GetDataDir_Data()
    {
        var parent = Directory.GetParent(Directory.GetCurrentDirectory()).Parent;
        string startDirectory = null;
        if (parent != null)
        {
            var directoryInfo = parent.Parent;
            if (directoryInfo != null)
            {
                startDirectory = directoryInfo.FullName;
            }
        }
        else
        {
            startDirectory = parent.FullName;
        }
        return startDirectory;
    }   
}

}

@kasriram

We tested the scenario in our environment and did not notice any issue. Would you kindly share what type of issue you have facing? Also, please make sure that you have following things installed in your Linux system before running the API:

  • package with Microsoft compatible fonts: ttf-mscorefonts-installer. (e.g. sudo apt-get install ttf-mscorefonts-installer )
  • libgdiplus Package (updated)

Thanks. We will check if both packages are installed and also get you more details in case we continue to face an issue.

@asad.ali

Our team checked and it looks like both packages are installed.

Confirmation from logs that packages are installed

root@cortex-converter-5bc447988f-88g4r:/app# apt-get install libgdiplus Reading package lists… Done Building dependency tree Reading state information… Done libgdiplus is already the newest version (4.2-2). 0 upgraded, 0 newly installed, 0 to remove and 35 not upgraded.

​root@cortex-converter-5bc447988f-88g4r:/app# apt-get install ttf-mscorefonts-installer Reading package lists… Done Building dependency tree Reading state information… Done ttf-mscorefonts-installer is already the newest version (3.6ubuntu2). 0 upgraded, 0 newly installed, 0 to remove and 35 not upgraded.

Here is the error we are receiving whem trying to save as docx

Below are the logs that the lib returns in the converter - null reference when trying to save as docx

image.jpg (299.3 KB)

@kasriram

The issue and stack trace seems related to missing fonts. However, we need to further investigate this issue in details and for the purpose, we have logged an investigation ticket as PDFNET-49063 in our issue tracking system. We will further look into its details and keep you posted with the status of its resolution. Please be patient and spare us some time.

We apologize for the inconvenience.

PS: You may please try adding this line before performing any operation and let us know if it helps:

Aspose.Pdf.Text.FontRepository.Sources.Add(new FolderFontSource("<user's path to ms fonts>"));

@asad.ali Thank you so much for your response! We will try adding the line you mentioned and try and will also await the outcome of your investigation

Hi is there any news , I also have this problem

@Armen23023

We are afraid that the issue could not get resolved yet. However, this ticket has been revived with your comments and we will inform you as soon as we make some progress towards its resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.