We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Add HTML String inside PDF using Aspose.PDF - HtmlFragment issue in AWS Lambda

Hi Team,

I am using below code to render HTML contents in a table cell. Below code is working fine in my local machine. But same code is failing in AWS Lambda and getting error like “Object reference not set to an instance of an object”. Could you please help me to resolve the issue?

   Document pdfDocument = new Document();
   Aspose.Pdf.Page page = pdfDocument.Pages.Add();
   Aspose.Pdf.Row row;
   Aspose.Pdf.Cell cell;
   Aspose.Pdf.Table pdfHeaderTable = new Aspose.Pdf.Table();
   row = pdfHeaderTable.Rows.Add();
   HtmlFragment hfComments = new HtmlFragment("<strong>Test Comments</strong>");
   cell = row.Cells.Add();
   cell.Paragraphs.Add(hfComments);
   page.Paragraphs.Add(pdfHeaderTable);
   MemoryStream msReportPDF = new MemoryStream();
   pdfDocument.Save(msReportPDF);

@SenthilRG27

Could you please share the complete stack trace of the Exception which you are facing. We will further investigate and address it accordingly.

@asad.ali,

Please refer below stack trace for HtmlFragment issue in AWS Lambda.

#=zMRzYY9R3Vl6yi4inP6a3ZK9oq9bFp$yGs87z4B8=.#=z4jxOEf2har94(#=zwKtsRxGnVDoV8lws$_y9iFx8Obx8y3LzXg== #=zqQs$llo=, Char #=zUiHEnlY=)
at #=zMRzYY9R3Vl6yi4inP6a3ZK9oq9bFp$yGs87z4B8=.#=z4jxOEf2har94(#=zwKtsRxGnVDoV8lws$_y9iFx8Obx8y3LzXg== #=zqQs$llo=)
at #=zQ7Q8eeBLfKm4pIi$snx96wjdjY9UuRL2pQ==.#=z3ElkS23J7iKd(#=zQ7Q8eeBLfKm4pIi$snx96wjdjY9UuRL2pQ== #=zYMNxJsg=, #=zvz6bct_zFRtU4jKgSpWfBnI4u5bBuOj$1NF8lY8= #=zev8rn6U=, #=zBVfxelXQGGsbjrH_NRuOwVHu$mRXqaAmpQ== #=zrjnqwZc=)
at #=zUC9n57FvIxd1Eh9jSJJra1ypVwZzDU_X1VwuY3g=…ctor(#=zQ7Q8ee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=zLYSUhy8= #=zOBAXFmY=, TimeSpan #=ze$_SWv4=)
at #=zE1ve9d8lC0QyRuf_nNrVnr54eeLb.Render(#=zcR9jE0eKS5zqmNI6sRXeq3ApV$1I #=z0BulzFY=, #=zLYSUhy8= #=zOBAXFmY=)
at #=ziYYDgCOI9XvuTjGmbALJ5m_MmaaU.#=z95NFQHI3v4mM(Stream #=zag2acIWiccKS, Document #=zb50g2w9M2HsL, HtmlLoadOptions #=z8XWl92SxULqa, IList1 #=zkJpTKIhFB6PT, String #=z8_CisyEchoH1, Matrix #=zvmdo1$U=) at Aspose.Pdf.FormattedFragment.#=zlwotkBg=(Double& #=ztWmGQ7Y=, Double& #=zMS3lGn4=, Boolean #=zCheTKATE5yMY, Double #=zkQO9vd8=, Double #=zt1K9aaM=, List1 #=zwlckaEo=, List1 #=z7yGQ9RGo$wriK1bMmg==, Int32& #=zaVPZHFHi7RgwKfTGCOgcjMmwSTaR, Page #=zZPNcMZI=, MarginInfo #=zJL8Li9Q=, Table #=zI$TNYMY=, Double& #=z73RngG8BPLOg, Boolean #=zoHL3Vdt6SPTB, Boolean #=z$3F1MZF_0Y0X) at #=z0C6pZ7eoF95JoTwe4XoB6gc=.#=zlwotkBg=() at Aspose.Pdf.Cell.#=z4D_NQvEJ7MrG(Table #=zI$TNYMY=, Double #=zkQO9vd8=, Page #=zZPNcMZI=, Double #=zt1K9aaM=, Double #=zMS3lGn4=, Boolean #=zD4QmsbE9SjEDmhbhLK8reFc=) at Aspose.Pdf.Row.#=zQTGiRSMcafw1OtmlnQ==(Table #=zI$TNYMY=, Page #=zZPNcMZI=, Double #=zMS3lGn4=, Double #=zt1K9aaM=, Int32 #=z1FEnmYU=) at Aspose.Pdf.Row.#=zlwotkBg=(Table #=zI$TNYMY=, Double& #=zMS3lGn4=, Double& #=ztWmGQ7Y=, Boolean #=zCheTKATE5yMY, Double #=zj4uLm9xheKsU, Double #=zt1K9aaM=, Page #=zZPNcMZI=, Int32& #=zYJfQ0USZ7GuP) at Aspose.Pdf.Table.#=zlwotkBg=(Double& #=ztWmGQ7Y=, Double& #=zMS3lGn4=, Boolean #=zCheTKATE5yMY, Double #=zQG05lxjd95HH, Double #=zt1K9aaM=, Page #=zZPNcMZI=, Boolean #=zpTlkjwg40Xjh, List1 #=zwlckaEo=)
at #=z0C6pZ7eoF95JoTwe4XoB6gc=.#=zlwotkBg=()
at Aspose.Pdf.Page.#=z1OX8yt8=(Page #=zZPNcMZI=)
at Aspose.Pdf.Page.#=zCcx3vQgWgN3SQQ21Sw==()
at Aspose.Pdf.Document.ProcessParagraphs()
at Aspose.Pdf.Document.#=zewfLdEs3iDvF(Stream #=zBp1$Iow=, SaveOptions #=z2aIFS7AYwCBX)
at Aspose.Pdf.Document.Save(Stream output)

@asad.ali

I have tried below code as well. But I am getting same error. Please deploy below code in AWS Lambda and test it. I am using 20.9.0 version of Aspose.PDF.

DataTable dt = new DataTable("Employee");
dt.Columns.Add("data", System.Type.GetType("System.String"));
DataRow dr = dt.NewRow();
dr[0] = "<li>Department of Emergency Medicine: 3400 Spruce Street Ground Silverstein Bldg Philadelphia PA 19104-4206</li>";
dt.Rows.Add(dr);
dr = dt.NewRow(); 
dr[0] = "<li>Penn Observation Medicine Service: 3400 Spruce Street Ground Floor Donner Philadelphia PA 19104-4206</li>";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "<li>UPHS/Presbyterian - Dept. of Emergency Medicine: 51 N. 39th Street . Philadelphia PA 19104-2640</li>";
dt.Rows.Add(dr);
Aspose.Pdf.Table tableProvider = new Aspose.Pdf.Table();
//Set column widths of the table
tableProvider.ColumnWidths = "400 50 ";
// Set the table border color as LightGray
tableProvider.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.5F, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
// Set the border for table cells
tableProvider.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.5F, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
Aspose.Pdf.MarginInfo margin = new Aspose.Pdf.MarginInfo();
margin.Top = 2.5F;
margin.Left = 2.5F;
margin.Bottom = 1.0F;
tableProvider.DefaultCellPadding = margin;
tableProvider.ImportDataTable(dt, false, 0, 0, 3, 1, true);
page.Paragraphs.Add(tableProvider);

@SenthilRG27

We have logged an issue as PDFNET-48870 in our issue tracking system for the sake of further investigation. We will further look into its details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We apologize for the inconvenience caused.