I want to convert html code to pdf so I use SelectPDF library, so my code is:
var converter = new HtmlToPdf();
var today = DateTime.UtcNow;
var fileName = $"test - {today}";
var doc = converter.ConvertHtmlString(html);
using var ms = new MemoryStream();
ms.Position = 0;
doc.Save(ms);
var res = ms.ToArray();
doc.Close();
return File(res, "application/pdf", fileName);
I tested using localhost and everything works well, always do a fast conversion (not more than 5 seconds).
The problem starts when I publish on the server, after the method executed sometimes (not always) it returns an error 500
Failed to load resource: the server responded with a status of 500 () Message: "Conversion error: Navigation timeout."
Is it a way always to get a fast result? I know I can expand load time as:
converter.Options.MaxPageLoadTime = 120;
But I want to convert it fast, 2 minutes for a simple HTML to pdf conversion is to much