PDF not generating with base 64 string

Hi Team,
I am using the below code to render the image to the PDF with a base 64 string, it is working in local but as soon as i am pushing the code to lambda, the function executes but the PDF is not generated.

string Bucket = Environment.GetEnvironmentVariable(“BUCKETNAME”);
string LicKey = Environment.GetEnvironmentVariable(“ASPOSEKEY”);
Aspose.Pdf.License lic = new Aspose.Pdf.License();
var licenceFile = SetKey(LicKey, Bucket).Result;
lic.SetLicense(new MemoryStream(licenceFile));

    string HTMLPDFTemplate = "<!DOCTYPE html>\r\n<html lang=\"en\"> \r\n   <head>  \r\n      " +
        "<meta charset=\"UTF-8\">\r\n      <meta name=\"viewport\"content=\"width=device-width, initial-scale=1.0\"> \r\n " +
        "     <title>Document</title>   \r\n     " +
        " <style> #customers { font-family: Arial, Helvetica, sans-serif; border-collapse: collapse; width: 100%; } " +
        "#customers td, #customers th { border: 1px solid #ddd; padding: 8px;}#customers tr:nth-child(even){background-color: " +
        "#f2f2f2;}#customers tr:hover {background-color: #ddd;}#customers th { padding-top: 12px; padding-bottom: " +
        "12px;text-align:left;background-color:#04AA6D; color: white;</style>   \r\n   </head>\r\n   <body>  
        "<img src=\"data:image/png;base64, xxxxxxxxxxxxxxxxxxx\"></div>\r\n      " </body></html>";
    HtmlLoadOptions htmlLoadOptions = new HtmlLoadOptions();
    Document pdfDocument = new Document();
    pdfDocument.Pages.Add().Paragraphs.Add(new HtmlFragment(HTMLPDFTemplate));


    MemoryStream stream = new MemoryStream();
    pdfDocument.Save(stream);
    return File(stream.ToArray(), "application/pdf", "test.pdf");
    //return File(stream.ToArray(), "application/pdf");

@dolphindua

Have you tried logging if stream is empty or not inside lambda function? We are afraid that we cannot try to replicate the information with these details. Can you please share some steps on how we can try to reproduce the issue in our environment? We will address it accordingly then.

Hi Team,

Thanks for your quick reply.

I have created an AWS lambda serverless function, this when triggered will be executed and should generate a PDF with some content and image/images.
In our code we have an HTML string which has all the data that needs to be converted to PDF. The image/images will be added as base64 string as per my above code snippet.
On further investigation the PDF generated by Lambda is corrupted and if we try to view the content on the lambda in notepad it is having base64 in it.
Best part in this is, the same code works properly and a PDF file is generated when we execute it in our local machine.

Let me know if we need more details.

Thanks
Dolphin

@dolphindua

The issue could be related to the missing fonts in the environment. Have you tried installing all the Windows fonts? Also, have you tried using Aspose.Pdf.Drawing instead of Aspose.PDF for .NET? Please share the PDF file that has been generated on the server so that we can investigate more and address the issue accordingly.

server.pdf (183.8 KB)

local.pdf (274.1 KB)

@asad.ali - Yes i did tried using ASPOSE.PDF.DRAWING and the result is same. Secondly to answer on installation of fonts, we tried doing the same but encountered same errors. I have attached the PDF generated from local and server.

@dolphindua

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

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.

Thanks @asad.ali

Hello, I understand the free support policy (ticket is not getting any priorisation nor comittment date), can you inform us where we are in the queue line - approx leadtime to get a fix?

@chloebrault

We are afraid that we cannot really share for certain how soon the investigation against this ticket would get completed. It not only depends upon the number of issues in the queue but also the complexity of the issue itself. Nevertheless, your concerns have been recorded and we will surely keep you posted with the progress of ticket resolution. Please spare us some time.

We are sorry for the inconvenience.

1 Like

Hello,
I got confirmation today that we are eligible to Paid Support with our company contract. Can you move the request into that backlog? or explain how to. Thank you

@chloebrault

You can open a ticket by logging into Paid Support (https://heldesk.aspose.com) while mentioning the issue ID shared in this thread. You can login there using same email address that was used to purchase the paid support subscription. Once you open ticket there, your issue will be escalated accordingly.