Create PDF failed from html

we have an application is working on windows system but when deployed to AWS lambda we got following error. We have latest Aspose.PDF.Drawing DLL

Please help

George

Object reference not set to an instance of an object. System.NullReferenceException: Object reference not set to an instance of an object.
at #=zsIyWioK31eoifD4h0oodXWInWWa_.#=zrCMBcrA=(#=zPXg6mQVFOnGPCqr9NpHT7TlK9AG2 #=zHRtK9WqhS0SP)
at #=zXvNf4yKsayXKe_0KW9ON_2E=.#=zR3eyU18=(#=zPXg6mQVFOnGPCqr9NpHT7TlK9AG2 #=zHRtK9WqhS0SP)
at #=zOCd4xIp8_cLiH3soa_luoDs=.#=zR3eyU18=(#=zPXg6mQVFOnGPCqr9NpHT7TlK9AG2 #=zHRtK9WqhS0SP)
at #=qRORQe7kwgNyo8AOmwnclh4z$TIYnPZrR5iEGYPwNPPk=.#=z3NTotJCuzcFbEqXzptaUMc_SBc2A(Object #=zFgqaTDc=)
at #=qRORQe7kwgNyo8AOmwnclh4z$TIYnPZrR5iEGYPwNPPk=.#=ziYjxLNtJd8hDvkstXqGYJ7717enH(MethodBase #=zFgqaTDc=, Boolean #=zVSzD2c0=)
at #=qRORQe7kwgNyo8AOmwnclh4z$TIYnPZrR5iEGYPwNPPk=.#=z3LB2Q1TZsQdBqkB1MCigQ1frOyxb(#=qRORQe7kwgNyo8AOmwnclh4z$TIYnPZrR5iEGYPwNPPk= #=zFgqaTDc=, #=qT26t5vOMKTF2HnEDSG0dt3I8NN1ZCwUgb929e45X9Kw= #=zVSzD2c0=)
at #=qRORQe7kwgNyo8AOmwnclh4z$TIYnPZrR5iEGYPwNPPk=.#=zb1YrD8aZvfuGtQ9dbTr5RehoGbPx5WDi6ZnAvng1aFRD()
at #=qRORQe7kwgNyo8AOmwnclh4z$TIYnPZrR5iEGYPwNPPk=.#=znNgxBVYeHIG4WYuAs$zvelk=(Boolean #=zFgqaTDc=)
at #=qRORQe7kwgNyo8AOmwnclh4z$TIYnPZrR5iEGYPwNPPk=.#=z3NTotJCuzcFbEqXzptaUMc_SBc2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aK3bPbYzNPfVhmsA==(Object[] #=zFgqaTDc=, Type[] #=zVSzD2c0=, Type[] #=zip_JpN8=, Object[] #=zHNsDfyY=)
at #=qRORQe7kwgNyo8AOmwnclh4z$TIYnPZrR5iEGYPwNPPk=.#=zhbn$lUGzNdOHnbIIiK2GWNXou0sap5uCEQpCcY1z_K9i(Stream #=zFgqaTDc=, String #=zVSzD2c0=, Object[] #=zip_JpN8=)
at #=qRORQe7kwgNyo8AOmwnclh4z$TIYnPZrR5iEGYPwNPPk=.#=zCcJBgRLXEFS4uMhrK8xLiumYqeyF(Stream #=zFgqaTDc=, String #=zVSzD2c0=, Object[] #=zip_JpN8=)
at Aspose.Pdf.Document.#=zHSU7TJ1r2p51(Stream #=z4RwsdAs=, SaveOptions #=zgCO5VhJBUdNb)
at Aspose.Pdf.Document.Save(Stream output)
at DocumentTransformation.Services.PdfService.<>c__DisplayClass10_0.b__0() in /vsts/agent/_work/13/s/DocumentTransformation.Logic/PdfService.cs:line 150

@gjin2023

Can you please share the sample HTML with us and sample code snippet too? We will test the scenario in our environment and address it accordingly.

test html is really simple :

<!DOCTYPE html><html lang='en' xmlns='http://www.w3.org/1999/xhtml'><head> <title>test pdf</title></head><body> <p>This is a test html page</p></body></html>

works on windows system but not aws lambda. must miss some lib?

var ms = new MemoryStream(unicode.GetBytes(request.Html));

public async Task<Stream> GeneratePdf(Stream stream)
{
    if(stream == null)
    {
        throw new ArgumentNullException("HtmlStream");
    }
    stream.Position = 0;
    stream.Seek(0, SeekOrigin.Begin);
    var options = new Aspose.Pdf.HtmlLoadOptions();
    // set page size to A4
    //A4 dimensions in points will be (842.4, 597.6)
    options.PageInfo.Height = 842.4;
    options.PageInfo.Width = 597.6;
    options.PageInfo.Margin.Left = 10.0;
    options.PageInfo.Margin.Right = 10.0;
    options.PageInfo.Margin.Top = 10.0;
    options.PageInfo.Margin.Bottom = 10.0;
    var pdfDocument = new Aspose.Pdf.Document(stream, options);
    var outStream = new MemoryStream();
    await Task.Run(() => pdfDocument.Save(outStream));
    return outStream;
}

@gjin2023

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-53730

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.

PS: Meanwhile, you can please try to make sure that all Windows fonts are present and installed properly in the environment.

@gjin2023

From the stack trace it looks like you are missing some standard MS fonts such as Arial, Times New Roman, Courier New etc. If AWS lambda is used with docker you can install them inside docker container by adding following command to a docker file : “RUN apt-get install ttf-mscorefonts-installer -y”.
Or you can copy fonts in a custom folder and set that folder as a font source :

FontRepository.Sources.Add(new FolderFontSource(string folderPath))