Performance Issue - Convert HTML to PDF.

Vamshi 151 Reputation points
2021-03-12T05:51:05.703+00:00

Hi Team,

I am generating a PDF report from the Web Application UI. On the click of button, the PDF report will be downloaded.
I have used Essential Objects (eo.pdf library) to convert HTML to PDF in the api service (.Net Core). The HTML data is 8100 records. Currently it is taking 95 seconds to process and download the PDF report and I believe this might vary based on the data size.
I am facing performance issues with the converting HTML to PDF and the Azure Gateway Timeout limit is set 90 seconds, which is causing Application time out issues.

Need inputs to fix this issue and advise if the below code can be improved/optimized so that the HTML TO PDF conversion is quicker and the REPORT IS DOWNLOADED IN 60 SECONDS.

Below is the code for reference.

ReportHelper.cs file:


public ReportFile GenerateReport(FileType fileType)
{
byte[] result = null;
string contentType = "text/html";
switch (fileType)
{
case FileType.Pdf:
string html = HtmlHelper.ToHtml(Data, ReportSetting, this);
var pdfHelper = new eoPdfHelper();
result = pdfHelper.ConvertToPdf(html, ReportSetting);
if (string.IsNullOrEmpty(ReportSetting.FileName))
{
if (!string.IsNullOrEmpty(ReportSetting.ReportHeaderTitle))
{
ReportSetting.FileName = $"{ReportSetting.ReportHeaderTitle}_Report.pdf";
}
else
{
ReportSetting.FileName = "Report.pdf";
}
}
contentType = "application/pdf";
break;
}
return new ReportFile() { Data = result, ContentType = contentType, FileName = ReportSetting.FileName };
}

eoPdfHelper.cs file:


using System.Drawing;
using System.IO;
using EO.Pdf;

namespace Report
{
public class eoPdfHelper: IPdfHelper
{
public byte[] ConvertToPdf(string html, ReportSetting reportSetting)
{
MemoryStream stream = new MemoryStream();
HtmlToPdfOptions options = new HtmlToPdfOptions();
options.RetrieveNodeText = false;
options.OutputArea = new RectangleF(0.5f, 0.5f, 9f, 12f);
if (reportSetting.ReportOrientation == ReportOrientation.Landscape)
{
options.PageSize = PdfPageSizes.A4;
}
HtmlToPdf.ConvertHtml(html, stream, options);
return stream.ToArray();
}
}
}

Thanks.

Community Center | Not monitored
0 comments No comments
{count} votes

Accepted answer
  1. cheong00 3,486 Reputation points Volunteer Moderator
    2021-03-12T06:13:51.02+00:00

    Your problem is on the performance issues of a 3rd party component, and I recommend you to ask in their forum instead for better support.

    When we don't have the library, we can't do anything to even guess what could help.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.