Use Aspose.PDF for .NET in AWS Linux machine - project cannot find the font to use

Hello, I would like to report a problem that occurred in an implementation, I used the latest version of aspose until 20.10.0, in the pro version. When deploying to an aws linux machine the project cannot find the font to use, in this sense, I inserted a script to install the font on the machine and tried in some ways to use it. however, it always gave an error that the source had not been found.

I tried to update the fonts folder using:

first example :
font = Aspose.Pdf.Text.FontRepository.OpenFont("~/.fonts/arial.ttf"); this not working.

second example:
FormattedText formatText = new FormattedText(string.Empty, System.Drawing.Color.Gray, System.Drawing.Color.Transparent, Path.Combine(path, “arial.ttf”), EncodingType.Identity_h, false, 7F); this not working.

third example:
this not working

namespace AsposeUtil.PDF
{
internal class PdfDocumentManager : PdfBaseClass
{
internal void AddFooterText(Stream outputStream, Stream inputStream, string footerText)
{

        StringBuilder text = new StringBuilder();

        foreach (string lineText in footerText.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
            text.Append(lineText);

        // Open document
        Document pdfDocument = new Document(inputStream);

        // Create footer
        TextStamp textStamp = new TextStamp(text.ToString());
        // Set properties of the stamp

       Aspose.Pdf.Text.Font font = Aspose.Pdf.Text.FontRepository.OpenFont("~/.fonts/arial.ttf");
        textStamp.TextState.Font = font;
        textStamp.BottomMargin = 10;
        textStamp.TextState.FontSize = 7F;
        textStamp.TextState.BackgroundColor = Color.Transparent;
        textStamp.TextState.ForegroundColor = Color.Gray;
        textStamp.WordWrap = true;
        textStamp.HorizontalAlignment = HorizontalAlignment.Center;
        textStamp.VerticalAlignment = VerticalAlignment.Bottom;
        // Add footer on all pages
        foreach (Page page in pdfDocument.Pages)
        {
            page.AddStamp(textStamp);
        }
        // Save updated PDF file
        pdfDocument.Save(outputStream);
    }
}

}

fourth example:
this not work

namespace AsposeUtil.PDF
{
internal class PdfDocumentManager : PdfBaseClass

{
    internal void AddFooterText(Stream outputStream, Stream inputStream, string footerText)
    {
        using (PdfFileMend pdfFileMend = new PdfFileMend())
        {
            pdfFileMend.BindPdf(inputStream);
            pdfFileMend.IsWordWrap = true;
            pdfFileMend.WrapMode = WordWrapMode.ByWords;




                Aspose.Pdf.Text.Font myFont = Aspose.Pdf.Text.FontRepository.OpenFont('caminho fonte');
                customFont.IsEmbedded = true;



                Aspose.Pdf.Text.TextState style = new Aspose.Pdf.Text.TextState();
                style.Font = customFont;
                style.FontSize = 10F;
                style.FontStyle = FontStyles.Regular;
                style.LineSpacing = 1;
                style.BackgroundColor = Aspose.Pdf.Color.Transparent;
                style.ForegroundColor = Aspose.Pdf.Color.Gray;



                StringBuilder text = new StringBuilder();
                foreach (string lineText in footerText.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
                    text.Append(lineText);



                Aspose.Pdf.Text.TextFragment frag = new Aspose.Pdf.Text.TextFragment(text.ToString());
                frag.IsInLineParagraph = true;
                frag.TextState.ApplyChangesFrom(style);



                foreach (Page page in pdfFileMend.Document.Pages)
                {
                    if (page.Footer == null)
                        page.Footer = new Aspose.Pdf.HeaderFooter();
                    page.Footer.Paragraphs.Add(frag);
                }
                pdfFileMend.Save(outputStream);
           



        }
    }
}

}

fifth example:
this not work
Aspose.Pdf.Text.FontRepository.Sources.Add(new FolderFontSource("~/.fonts"));

this not work

using (MemoryStream ms = new MemoryStream(Properties.Resources.Aspose_Total)) {
Aspose.Pdf.Text.Font myFont = Aspose.Pdf.Text.FontRepository.OpenFont(ms, Aspose.Pdf.Text.FontTypes.TTF);
myFont.IsEmbedded = true;
}

@vinicius.santos

We apologize for the inconvenience being faced.

Would you kindly share what type of issue/exception you are getting while running the code snippet. Also, if you are using an environment with docker file, would you please share that with us. We will test the scenario in our environment and address it accordingly.

Hello. When I run using the standard style font enum helvetica, the error is: Object reference not set to an instance of an object.

If I try to execute the method add a new font, or open the font, the error is: font not found exception.

@vinicius.santos

This seems like an environment specific issue as we tested at our side in CentOS 7 x64 environment and did not notice any issue. Could you please verify if your application is picking the file paths correctly? Please try to place the font files in project directory and use different/full path to access them. Please let us know if issue still persists, we will again test the scenario in our environment and address it accordingly.

Hello. I realized these tests also to pull the font directly from the project selection directory, even so the font was not loaded.

Good afternoon. I created an aspnet core 3.1 project to simulate the problem. This project pulls a standard pdf to insert a footer in it.
I inserted the font installation in the dockerfile and to test I pulled the font, comics, in the project. It seems to load the font, since the name of the font appears on the console. On the console the stream object also seems to be ok as shown in the print image. To simulate the test, I just ran the project through visual studio by selecting the Docker option.

The project is attached. I did not enter the license, but this error occurs in the same way, with the paid license.

image.png (160.6 KB)
project link: Vinicius Medeiros dos Santos / AsposeSampleIssue · GitLab

@vinicius.santos

We are already running some tests for stabilizing the API performance under .NET Core 3.1 environment. While we are looking into the issue you are facing, would you please try to use .NET Core 2.1/2.0 instead and let us know in case issue remains same.

Hello, I tested in version 2.1 core, the error remains the same.

@vinicius.santos

We have logged an investigation ticket as PDFNET-49034 in our issue tracking system for the sake of further analysis. We will look into details of this case and keep you informed about the status of ticket resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.

Any news in this case?

@lfbertucci

We are afraid that earlier logged ticket is not yet resolved. It will be surely reviewed and fixed on first come first serve basis and we will inform you within this forum thread as soon as we make some significant progress towards its resolution. Please give us some time.

We really apologize for the inconvenience.