"System.ArgumentException: At most 4 text fragments can be added in evaluation mode" with full Aspose.Total latest license

Hi we had Aspose.Total full license and we are using the same to generate PDF, Word and Excel documents. Even though we had a full license of aspose with us, while generating PDF’s, from last 4 months onwards we are facing this issue intermittently every week in any of the environment. Can you please help us asap as our clients are facing the issues in receiving notifications with pdf attachments.

Below is our code:

Void main ()
{
byte[] licenceBytes = GetLicenceBytes();
ValidateLicence(licenceBytes, fileExt);
GetHTMLtoPDF_V2(msHTMLStream, allowwatermark,isLandscape);
}
public byte[] GetLicenceBytes()
{
byte[] licence = null;
string asposeLicencePathUrl = null;
try
{
asposeLicencePathUrl = AppDomain.CurrentDomain.BaseDirectory + “/AsposeTotal/Aspose.Total.lic”;
licence = File.ReadAllBytes(asposeLicencePathUrl);
}
catch (CommunicationException ex)
{
// Log Exception here
throw;
}
return licence;
}

public void ValidateLicence(byte[] LicenceBytes, string fileExt)
{
try
{
Stream byteLicenceStream = new MemoryStream();
switch (fileExt)
{
case Gep.Cumulus.CSM.Entities.FileExtenstion.Word:
if (LicenceBytes == null)
{
BlValidateLicence = false;
break;
}
byteLicenceStream = new MemoryStream(LicenceBytes);
Aspose.Words.License licenseWord = new Aspose.Words.License();
licenseWord.SetLicense(byteLicenceStream);
BlValidateLicence = true;
break;

                case Gep.Cumulus.CSM.Entities.FileExtenstion.PPT:
                    if (LicenceBytes == null)
                    {
                        BlValidateLicence = false;
                        break;
                    }
                    byteLicenceStream = new MemoryStream(LicenceBytes);
                    Aspose.Slides.License licensePpt = new Aspose.Slides.License();
                    licensePpt.SetLicense(byteLicenceStream);
                    BlValidateLicence = true;
                    break;

                case Gep.Cumulus.CSM.Entities.FileExtenstion.PDF:
                  if (LicenceBytes == null)
                    {
                        BlValidateLicence = false;
                        break;
                    }
                    byteLicenceStream = new MemoryStream(LicenceBytes);
                    Aspose.Pdf.License licensePDF = new Aspose.Pdf.License();
                    licensePDF.SetLicense(byteLicenceStream);
                    BlValidateLicence = true;
                    break;

                case Gep.Cumulus.CSM.Entities.FileExtenstion.Excel:
                    if (LicenceBytes == null)
                    {
                        BlValidateLicence = false;
                        break;
                    }
                    byteLicenceStream = new MemoryStream(LicenceBytes);
                    Aspose.Cells.License licenseExcel = new Aspose.Cells.License();
                    licenseExcel.SetLicense(byteLicenceStream);
                    BlValidateLicence = true;
                    break;

                default:
                    BlValidateLicence = false;
                    break;
            }
        }
        catch (Exception)
        {
        }
    }

public byte[] GetHTMLtoPDF_V2(MemoryStream msHTMLStream, string allowwatermark = “”, bool isLandscape = false)
{
if (msHTMLStream == null)
throw new ArgumentNullException(“File Stream”);

        byte[] htmlBytes = null;

        Aspose.Pdf.HtmlLoadOptions htmlLoadOptions = new Aspose.Pdf.HtmlLoadOptions();

        htmlLoadOptions.PageInfo.Margin.Left = 15;
        htmlLoadOptions.PageInfo.Margin.Right = 15;
        htmlLoadOptions.PageInfo.Margin.Top = 15;
        htmlLoadOptions.PageInfo.Margin.Bottom = 15;
        htmlLoadOptions.PageInfo.Width = Aspose.Pdf.PageSize.A4.Width;
        htmlLoadOptions.PageInfo.Height = Aspose.Pdf.PageSize.A4.Height;
        htmlLoadOptions.InputEncoding = "UTF-8";

        if (isLandscape)
        {
            htmlLoadOptions.PageInfo.IsLandscape = isLandscape;
            htmlLoadOptions.PageInfo.Width = Aspose.Pdf.PageSize.A4.Height;
            htmlLoadOptions.PageInfo.Height = Aspose.Pdf.PageSize.A4.Width;
        }

        using (MemoryStream msPDFStream = new MemoryStream())
        {
            msHTMLStream.Position = 0;
            Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(msHTMLStream, htmlLoadOptions);

            int pagecount = pdfDocument.Pages.Count;
            if (pagecount > 1)
            {
                //create page number stamp
                PageNumberStamp pageNumberStamp = new PageNumberStamp();
                //whether the stamp is background
                pageNumberStamp.Background = false;
                pageNumberStamp.Format = "Page # of " + pdfDocument.Pages.Count;
                pageNumberStamp.BottomMargin = 6;
                pageNumberStamp.HorizontalAlignment = HorizontalAlignment.Center;
                pageNumberStamp.StartingNumber = 1;
                //set text properties
                pageNumberStamp.TextState.Font = FontRepository.FindFont("Arial");
                pageNumberStamp.TextState.FontSize = 9.0F;
                pageNumberStamp.TextState.FontStyle = FontStyles.Bold;
                pageNumberStamp.TextState.FontStyle = FontStyles.Italic;

                //add stamp to particular page
                //pdfDocument.Pages[1].AddStamp(pageNumberStamp);

                foreach (Page page in pdfDocument.Pages)
                {
                    page.AddStamp(pageNumberStamp);
                }
            }
            if (allowwatermark != "" || allowwatermark != null || allowwatermark.Length > 0)
            {
                Aspose.Pdf.Facades.Stamp aStamp = new Aspose.Pdf.Facades.Stamp();
                aStamp.Rotation = 45;
                aStamp.IsBackground = false;
                TextStamp textStamp = new TextStamp(allowwatermark);
                textStamp.Opacity = 0.2;
                textStamp.TextState.FontSize = 60.0F;
                textStamp.HorizontalAlignment = HorizontalAlignment.Center;
                textStamp.VerticalAlignment = VerticalAlignment.Center;
                textStamp.RotateAngle = aStamp.Rotation;
                textStamp.TextState.Font = FontRepository.FindFont("Arial");
                textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.Gray;

                // Adds Watermark in Page 1
                //pdfDocument.Pages[1].AddStamp(textStamp);
                //Adds Watermark in all Pages
                foreach (Page page in pdfDocument.Pages)
                {
                    page.AddStamp(textStamp);
                }
            }
            pdfDocument.Save(msPDFStream);
            htmlBytes = new byte[msPDFStream.Length];
            htmlBytes = msPDFStream.ToArray();
        }
        return htmlBytes;
    }

@syamsubhakar,

This type of the error occurs when the Aspose.Pdf license is not being applied. We can find Aspose.Pdf license code in the switch statement. We recommend our clients to apply license in some common area of the application project, e.g. application start event. However, if this does not help, then kindly create a small application project and make sure that it replicates this error in your environment, and then send us a Zip of this project. Your code has unknown objects and it is difficult for us to find the root cause. Your response is awaited.

We are creating the pdf data in html format and the same was given to generate pdf. We tried to replicate this issue in our local environments and no luck. I am providing complete error that we are receiving which may help you to provide the solution.

System.ArgumentException: At most 4 text fragments can be added in evaluation mode.
at Aspose.Pdf.Text.TextBuilder.(TextFragment , Int32 , Boolean )
at .VisitGlyphs(ApsGlyphs )
at Aspose.Rendering.ApsCompositeNode.Accept(ApsDocumentVisitor visitor)
at Aspose.Rendering.ApsCanvas.Accept(ApsDocumentVisitor visitor)
at Aspose.Rendering.ApsCompositeNode.Accept(ApsDocumentVisitor visitor)
at Aspose.Rendering.ApsCanvas.Accept(ApsDocumentVisitor visitor)
at Aspose.Rendering.ApsCompositeNode.Accept(ApsDocumentVisitor visitor)
at Aspose.Rendering.ApsCanvas.Accept(ApsDocumentVisitor visitor)
at Aspose.Rendering.ApsCompositeNode.Accept(ApsDocumentVisitor visitor)
at Aspose.Rendering.ApsPage.Accept(ApsDocumentVisitor visitor)
at .(List`1 , Document , LoadOptions , Boolean )
at Aspose.Pdf.Document.(Stream , LoadOptions )
at GEP.Cumulus.Impex.FileHelper.PDFHelper.GetHTMLtoPDF_V2(MemoryStream msHTMLStream, String allowwatermark, Boolean isLandscape)

In same type of question, i seen the answer saying to validate and line breaks like \n that need to be converted to \r\n or environment.newline. But in our scenario as we are using html template data as a request for pdf generation, we are using
tag for new line.

@syamsubhakar,

As we said in our earlier post, you need to apply license in some common area of the application. You are applying license inside the ValidateLicence method and once the execution of this method comes to an end, Aspose license objects will also be disposed. The error is about the evaluation limitations and you need to apply the license before loading an HTML document. Kindly send us your source HTML document. We will investigate and share our findings with you.

Here is the requested html document that failed with this issue
Aspose PO test.zip (13.4 KB)

@syamsubhakar,

We have tested your source HTML with the latest version 18.1 of Aspose.Pdf for .NET API and unable to replicate the said error in our environment. This is the output PDF: Output.pdf (241.4 KB). Kindly create a small application project and make sure that it reproduces this error in your environment, and then send us a Zip of this project. We will investigate and share our findings with you.

Here is the sample application that replicates our issue. Please provide the fix asap.

@syamsubhakar,

We are unable to view any file attachment with your post. There is an upload button in the header of the post editor. In case, if the attachment exceeds 3MB size limit, then upload this file to any free file sharer server, e.g. Google Drive, Dropbox etc. and share its download link with us.