question

Vamshi-5948 avatar image
0 Votes"
Vamshi-5948 asked ·

Performance Issue - Convert HTML to PDF.


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.

not-supported
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

cheong00 avatar image
0 Votes"
cheong00 answered ·

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.


·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.