Html to PDF not working on linux app service

We have this code where we convert html to pdf page . But this code fails on linux app service when we start adding logi image

private Document GetDetailsForPDFForm(BookingSheetDetailsDto surgeryBilling, Page pdfPage, Document pdfDocument)
{
var LogoImage = _hostingEnvironment.WebRootPath + “/FOI_Logo.png”;

 StringBuilder htmlBuilder = new StringBuilder();
 htmlBuilder.Append("<html><head>");
 htmlBuilder.Append("<style>");
 htmlBuilder.Append("head, html { margin: 0; padding: 0; }");
 htmlBuilder.Append($"body {{ width: {pdfPage.PageInfo.Width}; height: {pdfPage.PageInfo.Height}; margin: 0; padding: 0;}}");
 htmlBuilder.Append("table { width: 100%; border-collapse: collapse; }");
 htmlBuilder.Append("th, td { padding: 0px; text-align: left;} ");
 htmlBuilder.Append("th { color: black; font-weight: bold; }");
 htmlBuilder.Append(".icdCode-column { width: 25%; } .icdCodeDescription-column { width: 75%; }");
 htmlBuilder.Append(".cptCode-column { width: 15%; padding-top: 12px; padding-bottom: 12px; font-weight: bold; }");
 htmlBuilder.Append(".side-column, .units-column { width: 10%; padding: 12px 4px 12px 4px; font-weight: bold; }");
 htmlBuilder.Append(".levels-column { width: 15%; padding: 12px 4px 12px 4px; font-weight: bold; }");
 htmlBuilder.Append(".modifier-column { width: 10%; padding: 12px 4px 12px 4px; font-weight: bold; }");
 htmlBuilder.Append(".icdCodeLine-column {width:40%; padding: 12px 6px 12px 2px; font-weight: bold; word-wrap: break-word; overflow-wrap: break-word; word-break: break-word; white-space: normal;} ");
 htmlBuilder.Append(".cptCodedescription-column { width: 100%; border: none; }"); // Apply border: none only to CPT description
 htmlBuilder.Append("</style>");
 htmlBuilder.Append("</head><body>");

 if (!surgeryBilling.HospitalMRN.IsNullOrEmpty())
 {
     htmlBuilder.Append("<h3 style='display: inline; padding-right: 6px;'>Hospital MRN(Practice MRN) - </h3>");
     htmlBuilder.Append("<span>").Append(surgeryBilling.HospitalMRN).Append(""</span>);
     htmlBuilder.Append("<hr/>");
 }
 if (!surgeryBilling.AnesthesiaType.IsNullOrEmpty())
 {
     htmlBuilder.Append("<h3 style='display: inline; padding-right: 6px;'>Anesthesia Type - </h3>");
     htmlBuilder.Append("<span>").Append(surgeryBilling.AnesthesiaType).Append(""</span>);
     htmlBuilder.Append("<hr/>");
 }
 if (!surgeryBilling.SurgeryDescription.IsNullOrEmpty())
 {
     htmlBuilder.Append("<h3>Procedure/Surgery Description</h3>");
     htmlBuilder.Append("<p>").Append(surgeryBilling.SurgeryDescription).Append("</p>");
     htmlBuilder.Append("<hr/>");
 }
 if (!surgeryBilling.SpecialEquipmentOrSupplies.IsNullOrEmpty())
 {
     htmlBuilder.Append("<h3>Special Equipments Or Supplies</h3>");
     htmlBuilder.Append("<p>").Append(surgeryBilling.SpecialEquipmentOrSupplies).Append("</p>");
     htmlBuilder.Append("<hr/>");
 }
 htmlBuilder.Append("<h3>Diagnosis Information</h3>");
 htmlBuilder.Append("<table><tr><th class='icdCode-column'>DX Code</th><th class='icdCodeDescription-column'>Description</th></tr>");
 foreach (var icdDetails in surgeryBilling.ICDCodeDetails)
 {
     htmlBuilder.Append("<tr><td class='icdCode-column'>").Append(icdDetails.ICDCode).Append("</td>");
     htmlBuilder.Append("<td class='icdCodeDescription-column'>").Append(icdDetails.ICDCodeShortDescription).Append("</td></tr>");
 }
 htmlBuilder.Append("</table>");

 htmlBuilder.Append("<h3>Procedure Information</h3>");
 htmlBuilder.Append("<table><tr><th class='cptCode-column'>CPT Code</th><th class='icdCode-column'>DX Code</th>");
 htmlBuilder.Append("<th class='side-column'>Side</th><th class='levels-column'>Levels</th><th class='units-column'>Unit</th><th class='modifier-column'>Modifier</th></tr>");
 foreach (var cptDetails in surgeryBilling.CPTCodeDetails)
 {
     htmlBuilder.Append("<tr><td class='cptCode-column'>").Append(cptDetails.CPTCode).Append("</td>");
     htmlBuilder.Append("<td class='icdCodeLine-column'>").Append(cptDetails.ICDCodesForLineItem).Append(" </td>");
     htmlBuilder.Append("<td class='side-column'>").Append(cptDetails.Side).Append("</td>");
     htmlBuilder.Append("<td class='levels-column'>").Append(cptDetails.Levels).Append("</td>");
     htmlBuilder.Append("<td class='units-column'>").Append(cptDetails.Units).Append("</td>");
     htmlBuilder.Append("<td class='modifier-column'>").Append(cptDetails.ModifiersForLineItem).Append("</td></tr>");
     htmlBuilder.Append("<tr><td colspan='5' class='cptCodedescription-column'>").Append(cptDetails.CPTCodeLongDescription).Append("</td></tr>");
 }
 htmlBuilder.Append("</table>");
 htmlBuilder.Append("</body></html>");

string htmlString = htmlBuilder.ToString();

HtmlLoadOptions htmlLoadOptions = new HtmlLoadOptions
{
PageInfo = new PageInfo
{
Width = PageSize.PageLetter.Width,
Height = PageSize.PageLetter.Height,
},
InputEncoding = “UTF-8”
};

Document document = new Document(new MemoryStream(Encoding.UTF8.GetBytes(htmlString)), htmlLoadOptions);

return document;
}

@nikhilprabhu100

It seems that you are encountering issues with converting HTML to PDF in a Linux app service, particularly when adding a logo image. Here are some steps and considerations that might help you resolve this issue:

  1. File Path: Ensure that the path to the logo image is correct and accessible in the Linux environment. The _hostingEnvironment.WebRootPath may not point to the expected directory in a Linux app service. You might want to use an absolute path or verify the relative path based on your deployment structure.

  2. Image Format: Check if the image format is supported and correctly handled by the Aspose.PDF library. PNG is generally supported, but ensure that the image is not corrupted and is accessible.

  3. Permissions: Verify that the application has the necessary permissions to read the image file. In Linux environments, file permissions can often lead to access issues.

  4. HTML Content: When constructing the HTML string, ensure that the image tag is correctly formatted. For example:

    <img src="path/to/FOI_Logo.png" alt="Logo" />
    

    Make sure the src attribute points to the correct location of the image.

  5. Debugging: Add logging to check if the HTML string is being generated correctly and if the image path is valid. This can help identify if the issue lies in the HTML generation or the PDF conversion process.

  6. Testing Locally: If possible, test the same code locally in a Linux environment to see if the issue persists. This can help isolate whether the problem is specific to the app service.

  7. Aspose Support: If the issue continues, consider reaching out to Aspose support with detailed information about the error messages or behavior you are experiencing. They may have specific insights or updates regarding compatibility with Linux environments.

By following these steps, you should be able to troubleshoot the issue with HTML to PDF conversion in your Linux app service. If you have any specific error messages or behaviors, feel free to share them for more targeted assistance.