Exception while adding Stamp to PDF file opened by Aspose - Linux docker env

Im Using .NET Core 3.1.

Im loading PDF from HTML file like this:

string htmlContent = File.ReadAllText("someFileWithHtml.txt");
string filename = Guid.NewGuid() + ".pdf";

var options = new AsposeHtml.Saving.PdfSaveOptions();                           
options.PageSetup.AnyPage.Margin.Bottom = new LengthOrAuto(Unit.FromPixels(85));
options.PageSetup.AnyPage.Margin.Top = new LengthOrAuto(Unit.FromPixels(75));   
options.PageSetup.AnyPage.Margin.Left = new LengthOrAuto(Unit.FromPixels(20));  
options.PageSetup.AnyPage.Margin.Right = new LengthOrAuto(Unit.FromPixels(20)); 
                                      
Aspose.Html.Converters.Converter.ConvertHTML(htmlContent, ".", options, filename);

Then, i want to add Stamp into this file:

var fileStamp = new PdfFileStamp();   
var stamp = new Stamp();              
                                      
fileStamp.BindPdf(filename);          
                                      
stamp.BindLogo(new FormattedText(     
    "Hello World",
    new FontColor(0, 0, 0),           
    FontStyle.TimesRoman,             
    EncodingType.Cp1250,              
    false,                            
    12));                             
                                      
stamp.SetOrigin(220, 800);            
                                      
fileStamp.AddStamp(stamp);            
                                      
fileStamp.Save(filename);             
fileStamp.Close();                    

from this code i get an exception:

at Aspose.Pdf.Text.Font..ctor(#=zNHBl9bv5dKBFxtt9xgExszk= #=zg4LwFFM=)
   at #=zrqioYeoeEV9SrAkxSuXwlXH5Ifyvlj21WdquE7oNTcGPoqO1Sd3yyi8=.#=zdLqnfTBuN$M4C$2UFip31dB2LdAV(String #=zpnc7MyM=, Font #=zg4LwFFM=, Font& #=zMKyPsWYDEY$fJObf78seVyY=)
   at Aspose.Pdf.Text.TextSegment.set_Text(String value)
   at Aspose.Pdf.Text.TextFragment.set_Text(String value)
   at Aspose.Pdf.TextStamp.Put(Page page)
   at Aspose.Pdf.Page.AddStamp(Stamp stamp)
   at Aspose.Pdf.Facades.PdfFileStamp.#=z3WlzkzaWU5CT(Stamp #=zT1DBf1I=, Int32 #=zZfJaCY7K7AMe)
   at Aspose.Pdf.Facades.PdfFileStamp.#=z3WlzkzaWU5CT(Stamp #=zT1DBf1I=)
   at Aspose.Pdf.Facades.PdfFileStamp.AddStamp(Stamp stamp)


.. and so on...

My question is, how to add Stamp using Aspose.PDF on Linux? It happend to any file that i uploading to my method (as htmlContent). I cant attach any html file as example

@michasacuer

Please make sure that all windows fonts are installed on the Linux system where you are using the API. Also, please make sure to install libgdiplus package. In case issue still persists, please share your sample .html file in a .zip format. We will test the scenario in our environment and address it accordingly.

@asad.ali

Tkanks for your replay. But why i can create PDF file that uses Times News Roman by default (IT looks like TNR in output pdf file) but when im loading that pdf it crashes on Stamp Class because it dont have font that aspose used seconds ago? What magic exist under the Hood? Why Aspose.HTML can create text from HTML content and Aspose.PDF cant create text ? IT doesnt matters what HTML u pass to this, it will crash on the same way

@asad.ali

Here is the file in attachment. Save this file as i show you above, then try to add Stamp.

someFileWithHtml.zip (15.1 KB)

You can even use:

stamp.BindLogo(new FormattedText "Hello World")); 

Without any parameters and it wont work.

EDIT:

Here is method (maybe it will be easier for you):

// html content is readed txt file like that:
string htmlContent = File.ReadAllText("someFileWithHtml.txt");
...
public byte[] Generate(string htmlContent)
{
     byte[] outputFile;
     string filename = Guid.NewGuid() + ".pdf";

     var options = new Aspose.Html.Saving.PdfSaveOptions();
     options.PageSetup.AnyPage.Margin.Bottom = new LengthOrAuto(Unit.FromPixels(85));
     options.PageSetup.AnyPage.Margin.Top = new LengthOrAuto(Unit.FromPixels(75));
     options.PageSetup.AnyPage.Margin.Left = new LengthOrAuto(Unit.FromPixels(20));
     options.PageSetup.AnyPage.Margin.Right = new LengthOrAuto(Unit.FromPixels(20));
     Aspose.Html.Converters.Converter.ConvertHTML(htmlContent, ".", options, filename);

    var fileStamp = new PdfFileStamp();
     var stamp = new Stamp();

     fileStamp.BindPdf(filename); 
            
     stamp.BindLogo(new FormattedText(
                "Hello World",
                new FontColor(0, 0, 0), 
                FontStyle.TimesRoman,
                EncodingType.Cp1250,
                false,
                12));
            
     stamp.SetOrigin(220, 800);
            
     fileStamp.AddStamp(stamp);
            
     fileStamp.Save(filename);
     fileStamp.Close();

    outputFile = File.ReadAllBytes(filename);

    reutn outputFile;
 
}

@asad.ali

How i should install that windows fonts on my docker image to be compatible with Aspose?

@michasacuer

You can copy/paste all your windows fonts in your docker environment. Also, you can install Microsoft compatible fonts: ttf-mscorefonts-installer. (e.g. sudo apt-get install ttf-mscorefonts-installer )

Regarding investigation of the scenario in our environment. Would you please share your docker file also in .zip format with us.