Convert Html to Pdf: Aspose.Pdf italic font style is not getting reflect in output pdf on Cloud Foundary (Linux based container)

I am using aspose.pdf to convert html file to pdf file, but somehow font-family like “Cambria”,“Georgia”,“Times New Roman” and ITALIC font-style are not reflecting in output pdf that generates from aspose.pdf library.

Athough I kept (.ttf) font files for “Cambria”,“Georgia”,“Times New Roman” in same project folder.

Could you please look at this and help me to fix it?

Application written in C# (.NET 6)
Env: Clound Foundary (Linux based container)
Code:
try
{
Aspose.Pdf.License license = new Aspose.Pdf.License();
string licensepath = AppContext.BaseDirectory + “Aspose.Total.NET.lic”;
inputFile = $“{Constants.HEADERTEXT} {inputFile}”;
license.SetLicense(licensepath);
byte[] byteArray = Encoding.ASCII.GetBytes(inputFile);
using (MemoryStream stream = new MemoryStream(byteArray))
{
// Set page size A3 and Landscape orientation;
HtmlLoadOptions options = new HtmlLoadOptions()
{
PageInfo = { Width = 1200, Height = 1191, IsLandscape = true }

                    };
                    
                    using (Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(stream, options))
                    {
                        FontRepository.Sources.Add(new FolderFontSource(AppContext.BaseDirectory));
                        pdfDocument.Save(outputFile);
                    }
                }
                break; // success!
            }
            catch(Exception ex)
            {
Console.WriteLine($"GeneratePDF: Failed, inputFile={inputFile} Attempt={retry}, error= {ex.ToString()}");

}

@pps2794

Would you please try below suggestions and share your feedback with us:

  • Move below line of code right after you are setting the license:
FontRepository.Sources.Add(new FolderFontSource(AppContext.BaseDirectory));
  • Use Aspose.Pdf.Drawing instead of Aspose.PDF for .NET

After making these changes, I am still unable to get expected result.
New code:
Aspose.Pdf.License license = new Aspose.Pdf.License();
string licensepath = AppContext.BaseDirectory + “Aspose.Total.NET.lic”;
Console.WriteLine($“PDf is going to export, outputFile={outputFile}, Attempt={retry}”);
// add stylesheet in header in order to apply CSS in output pdf
inputFile = $“{Constants.HEADERTEXT} {inputFile}”;
license.SetLicense(licensepath);
FontRepository.Sources.Add(new FolderFontSource(AppContext.BaseDirectory));
byte[] byteArray = Encoding.ASCII.GetBytes(inputFile);
using (MemoryStream stream = new MemoryStream(byteArray))
{
// Set page size A3 and Landscape orientation;
HtmlLoadOptions options = new HtmlLoadOptions()
{
PageInfo = { Width = 1200, Height = 1191, IsLandscape = true }

                    };
                    
                    using (Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(stream, options))
                    {
                        pdfDocument.Save(outputFile);
                    }
                }

Also, I am already using the Aspose.PDF.Drawing Nuget package (version - 23.4.0) for this project.

@pps2794

Have you tried using the latest version? Please share your sample files and sample docker file with us as well in case issue is still persisting with the latest version as well. We will test the scenario in our environment and address it accordingly.

After upgrading aspose.pdf.drawing to 23.11.0, the required fonts getting applied successfully, but sometimes, we are getting below error which caused the container got stuck because OOM. It took around 5 hours to error out the pdf ( code statement - pdfDocument.Save(outputFile)) which got failed with the below error. I have attached the html file that to be exported to PDF file.
Example.zip (25.1 KB)

Error= System.OutOfMemoryException: Exception of type ‘System.OutOfMemoryException’ was thrown. at #=zFpzQ$jMSx_9ZKnSykfCcEQmj1BKWX1eZIw==.#=zqRhCpKWxYxqTd39lbQ==(#=zJ3vmM7qiKmHn5QQBWTwjvIV8T_SaaenURw== #=zUFbvZ0U=, #=zMLpeDD7vvDhBYv90tPgQBMut1jeaeat1CrhEpHU= #=zbhDnceA=, #=z_V0mFtjWgXkri5MRWJFp3lm8Sw6dAJGdSg== #=zkQZ5UHZSUrXB, #=z82Uqe8qnsYNUy1voAX7B2aP8iwBC #=zYsRuNE_22Orz, #=z2Bl_RWYlgG2alRzFejXkn4abXk38xrkr$g== #=zcUe9JJc_A6JF, #=zxWdDpdsMl9bjgvmt4vf1aOf8w0EG_rP4PA== #=z$l1T50g=, Boolean #=zRejrGdVvBO3_, List1 #=zZYUgcSAO5O54, List1 #=ze47k5eC7zo7N, List1 #=zFHWidwuiXywV, List1 #=zKoU7H6Zgw1DUwpkkqg==) at #=zWRUhCzXyojszmBoA1vGhAfu0pXhdJdzPow==.#=zXGkborlOb6J6.MoveNext() at Aspose.Pdf.Document.#=zRFhCE8k=(Stream #=zOa53BXo=, LoadOptions #=zbwxujTc=)

System details: (Linux Container - Cloud Foundary)
RAM Memory: 6GB
Disc Memory: 4GB

Do we need to manage memory calling by gc.collect() explicitly?

Please advise.

@pps2794

Thanks for sharing the sample HTML file. Please try with 24.3 version of the API as it is the latest one. Also, as requested earlier - please share your docker file as well in case issue still persists. We will log an investigation ticket and share the ID with you.

@asad.ali
I have downgraded the aspose.pdf.drawing from 23.11.0 to 23.4 version, but not sure if it works for us.

I have also attached the halfpipe.io and pipeline.yml file.
halfpipe.zip (3.1 KB)

@asad.ali
Downgrading aspose.pdf from 23.11.0 to 23.4 version is creating font family/styles issue now, some font family and ITALIC font style is not getting reflected in output pdf on CF environment.

For now, I have rollbacked aspose.pdf version back to 23.11.0.

@pps2794

We extremely apologize for the typo. We meant to say 24.3 instead of 23.4. Please give 24.3 version and try and let us know if it helps. We are sorry for the trouble.

@asad.ali
I don’t see aspose.pdf.drawing version 24.3 in NuGet package manager, so I have installed/upgraded it to 24.2.

image.png (29.8 KB)

@asad.ali

Also, we are continuously facing processing time (taking 4-5 hours on pdfDocument.Save(outputFile) ) and eventually, got failed with out of memory exception with both 23.11 and 24.2 aspose.pdf versions. see attached input html file.
example2.zip (42.9 KB)

For now, we have rollbacked aspose.pdf version to 23.4 on CF environment with below exceptional issues:

  • font family
  • font style ITALIC
    These changes do not get applied in output pdf with 23.4.

@pps2794

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-56846

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@asad.ali any updates on this?

@pps2794

The ticket has been logged under the free support model where it will be prioritized on a first come first serve basis. As soon as we make some updates in this regard, we will inform you. Please be patient and spare us some time.

1 Like

@asad.ali Any updates now?

@pps2794

We are afraid that no significant progress has been made yet towards ticket resolution. Once we have some updates, we will inform you. Please spare us some time.

@asad.ali any updates on this?

@pps2794

We are sorry that no updates are available yet about the ticket resolution. As soon as we make some progress in this regard, we will let you know. We apologize for the inconvenience.

@asad.ali
Any updates on this improvement?

We are still getting below error for 5-6 HTMLs/examples and taking so much time to fail, see attached one of the html examples.
Example_08202024.zip (57.8 KB)

:
Error= System.OutOfMemoryException: Exception of type ‘System.OutOfMemoryException’ was thrown. at #=zFpzQ$jMSx_9ZKnSykfCcEQmj1BKWX1eZIw==.#=zqRhCpKWxYxqTd39lbQ==(#=zJ3vmM7qiKmHn5QQBWTwjvIV8T_SaaenURw== #=zUFbvZ0U=, #=zMLpeDD7vvDhBYv90tPgQBMut1jeaeat1CrhEpHU= #=zbhDnceA=, #=z_V0mFtjWgXkri5MRWJFp3lm8Sw6dAJGdSg== #=zkQZ5UHZSUrXB, #=z82Uqe8qnsYNUy1voAX7B2aP8iwBC #=zYsRuNE_22Orz, #=z2Bl_RWYlgG2alRzFejXkn4abXk38xrkr$g== #=zcUe9JJc_A6JF, #=zxWdDpdsMl9bjgvmt4vf1aOf8w0EG_rP4PA== #=z$l1T50g=, Boolean #=zRejrGdVvBO3_, List1 #=zZYUgcSAO5O54, List 1 #=ze47k5eC7zo7N, List1 #=zFHWidwuiXywV, List 1 #=zKoU7H6Zgw1DUwpkkqg==) at #=zWRUhCzXyojszmBoA1vGhAfu0pXhdJdzPow==.#=zXGkborlOb6J6.MoveNext() at Aspose.Pdf.Document.#=zRFhCE8k=(Stream #=zOa53BXo=, LoadOptions #=zbwxujTc=)

This time it is getting failed on Windows OS as well.

@pps2794

We are afraid that no progress could be made towards ticket resolution due to other issues in the queue. However, your concerns have been recorded already as well as the information that you just provided. We will surely consider them during investigation and let you know as soon as the ticket is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.