Object reference not set to an instance of an object for Aspose.PDF (.Net)

We are using AsposePdf.Net to generate PDF File using HTML tags. Below is the code snipped -

 var document = new Document
                {
                    PageInfo = new PageInfo { Margin = new MarginInfo(28, 28, 28, 42) }
                };

                var pdfPage = document.Pages.Add();

             HtmlFragment gradeListing = new HtmlFragment("<div><label style='font-weight:bold;font-size: 18px;'>Grade Listing</label><label style='float:right;margin-right:10px;'>Report generated on : " + DateTime.Now.Date.ToString("dd/MM/yyyy") + "</label></div>");
                gradeListing.Margin.Bottom = 10;
                pdfPage.Paragraphs.Add(gradeListing);

                Table table = new Table()
                {
                    // Set column auto widths of the table
                    ColumnWidths = "16% 14% 14% 13% 13% 30%",

                    // Set cell padding
                    DefaultCellPadding = new MarginInfo(5, 5, 5, 5), // Left Bottom Right Top
                                                                       // Set the table border color as Green
                    Border = new BorderInfo(BorderSide.All, .5f, Color.Green),
                    // Set the border for table cells as Black
                    DefaultCellBorder = new BorderInfo(BorderSide.All, .2f, Color.Green)
                };

                var headerRow = table.Rows.Add();
                headerRow.DefaultCellTextState.FontStyle = FontStyles.Bold;
                headerRow.DefaultCellTextState.HorizontalAlignment = HorizontalAlignment.Center;
                headerRow.Cells.Add("Student Name");
                headerRow.Cells.Add("Grade Level");
                headerRow.Cells.Add("Enrollment Date");
                headerRow.Cells.Add("Status");
                headerRow.Cells.Add("Course");
                headerRow.Cells.Add("Course Section");

               table.RepeatingRowsCount = 1;

                 // Add row to table
                    var row = table.Rows.Add();
                    // Add table cells
                    row.Cells.Add("Debasis");
                    row.Cells.Add("G1:);
                    row.Cells.Add("2020-01-01");
                    row.Cells.Add("Admitted");
                    row.Cells.Add("Language");
                    row.Cells.Add("Section 1");
               

                pdfPage.Paragraphs.Add(table);

                using (var streamOut = new MemoryStream())
                {
                    document.Save(streamOut, new PdfSaveOptions());
                    return streamOut.ToArray();
                }

We are using .Net Core 3.1 for API Project and installed Aspose.PDF 20.12 using Nuget Package. We return byte[] through the web api. The entire code block is work perfectly in the Windows development machine. But when we deployed the API in the AWS Docker container, it throws the error Object Reference not set to an instance of an object, Below is the error stack -

System.NullReferenceException: Object reference not set to an instance of an object.
   at #=zWba3WGT5JGeC9CRN0Zm68ldIOugB.#=zTsv_dFc=(#=zA_xYGrix2GD7PJ99mdZ2ZL0VzGhD #=zWjJ_zW8q$xu4)
   at #=zKMoyN6QAK3friV31_0qk4Zo=.#=z9iAw0y0=(#=zA_xYGrix2GD7PJ99mdZ2ZL0VzGhD #=zWjJ_zW8q$xu4)
   at #=qI1AZwCL5S4CLXcQkWTDvVBzYELadZ9rkC1h9GSvMWMY=.#=zbBNtaSzHJjj5KxLq26FeMrnqZQxL6ia0qg==(Object #=z_2OfPOA=)
   at #=qI1AZwCL5S4CLXcQkWTDvVBzYELadZ9rkC1h9GSvMWMY=.#=z2gGtVCx5pC05Zu$0$JfgPUG19eIt(MethodBase #=z_2OfPOA=, Boolean #=z2V_2HIM=)
   at #=qI1AZwCL5S4CLXcQkWTDvVBzYELadZ9rkC1h9GSvMWMY=.#=zGllJi2yqNVjb0cD4qi6Bpzs=(#=qI1AZwCL5S4CLXcQkWTDvVBzYELadZ9rkC1h9GSvMWMY= #=z_2OfPOA=, #=qdvjf$2NVHNG_WicTUAgO8VNxlrl2xyqxtAGueWQ_oYI= #=z2V_2HIM=)
   at #=qI1AZwCL5S4CLXcQkWTDvVBzYELadZ9rkC1h9GSvMWMY=.#=zxGpiXu7FdDcDr36cq6I7I$8ZVxbumx5JtYhb9mc=()
   at #=qI1AZwCL5S4CLXcQkWTDvVBzYELadZ9rkC1h9GSvMWMY=.#=zh9X8syN_UiMiZj9qvyQhc8g=(Boolean #=z_2OfPOA=)
   at #=qI1AZwCL5S4CLXcQkWTDvVBzYELadZ9rkC1h9GSvMWMY=.#=zbBNtaSzHJjj5KxLq26FeMrnqZQxL6ia0qg==(Object #=z_2OfPOA=)
   at #=qI1AZwCL5S4CLXcQkWTDvVBzYELadZ9rkC1h9GSvMWMY=.#=zYa7qB9$kAz40m$QJ0hf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im_4b9Q==(Object[] #=z_2OfPOA=, Type[] #=z2V_2HIM=, Type[] #=zZNaGjxE=, Object[] #=zOySp_CY=)
   at #=qI1AZwCL5S4CLXcQkWTDvVBzYELadZ9rkC1h9GSvMWMY=.#=zLVcY78RMYKibXi$XWe3wigsjeuTJ(Stream #=z_2OfPOA=, String #=z2V_2HIM=, Object[] #=zZNaGjxE=, Type[] #=zOySp_CY=, Type[] #=zG1KP1dE=, Object[] #=zEPSjRi0=)
   at #=qI1AZwCL5S4CLXcQkWTDvVBzYELadZ9rkC1h9GSvMWMY=.#=zn1l9aia4ggUK7Jm76g==(Stream #=z_2OfPOA=, String #=z2V_2HIM=, Object[] #=zZNaGjxE=)
   at #=qI1AZwCL5S4CLXcQkWTDvVBzYELadZ9rkC1h9GSvMWMY=.#=zaUnc2em4jLcegg7HMFS_t6k=(Stream #=z_2OfPOA=, String #=z2V_2HIM=, Object[] #=zZNaGjxE=)
   at Aspose.Pdf.Document.#=zlFihzg7fniGz(Stream #=zob$eTI8=, SaveOptions #=znQ1_uSMlhiaM)
   at Aspose.Pdf.Document.#=zcGvhIneymP7r(Stream #=zfIE6hne5GAUv, SaveOptions #=zBlNOmoM=)
   at Aspose.Pdf.Document.Save(Stream outputStream, SaveOptions options)
   at Markers.Api.CannedReport.Controllers.StudentGradeListingController.ConvertStudentGradeListingsToByteArray(IList`1 studentGradeListing) in Controllers/StudentGradeListingController.cs:line 180

We are planning to purchase the license for the Aspose.PDF. But before purchasing the license, we need to solve this issue to check the deployment.

@debasis.saha

Would you kindly try to make sure that all Windows Essential Fonts are present in the environment where exception is being thrown. You can upload windows fonts to your AWS environment as API needs them during PDF generation. Please let us know if you still face any issue.

@asad.ali , I am also getting the same issue. Please help me out how we can resolve that issue after running the code in the docker image. I have the Aspose.Total.NET license.

@shmishra

Would you please make sure that you are installing all Windows fonts as well while running the docker? You can check for the package like msttcorefonts. Also, please try to use Aspose.Pdf.Drawing instead of Aspose.PDF. If issue still persists, please share your sample docker file and the code snippet for our reference. We will further proceed accordingly.

@asad.ali
Thank you so much , this issue has been resolved. But after generating pdf, I am using other library for pdf accessibility which is causing the error. So I am planning to replace that with aspose if aspose also supports accessibility in PDF. So can we add accessibility tags in the pdf using aspose.pdf.

@shmishra

Yes, Aspose.PDF also supports tagged PDFs. Please check the linked section in the API documentation for more information.