We use Spire.Pdf to generate Pdf Files from Html-Strings, using the ChromeHtmlConverter:
https://www.e-iceblue.com/Tutorials/NET/Spire.PDF-for-.NET/Program-Guide/Conversion/C-Convert-HTML-to-PDF-using-ChromeHtmlConverter.html
Unfortunatly we ran in some Problems. Our service runs inside a Linux-Container, but the Problem also appears when we run our software in windows 10, 64-bit debugging with VS.
This Problem can happen at any time, but we were able to reproduce it by sending multiple requests in short notice (5x per script) on the endpoint of our service.
This seems to crash either chrome or the ChromeHtmlConverter itself.
At first the requests seem to get lost, we dont run into any exception which our code could catch, we dont run into any timeout which we set for the ChromeHtmlConverter.
We never get a response from the converter.ConvertToPdf call and also the output Log just stops at a specific point.
This is only reproducable in our linux container:
Once an error occured, later calls fail with the exception "No valid Base64", which is not true since the exact same request works other times.
The service doesnt "fix" itself anymore, once it is in this state only a restart of the container fixes this issue.
Can you please support us in this case?
How to reproduce under Windows:
- Have Chrome installed
- Create new Solution with a Project "ASP.NET Core Web API" with these options:
-> Framework: Net 8.0
-> Authentication Type: None
-> Configure for HTTPS
-> Enable OpenAPI Support
-> UseControllers
- Install "Spire.PDFfor.NETStandard" Version 11.9.17 with nuget
- Create a simple class & interface with a parameterless void, with the Code from your page (Including the Logger, so under "Generate Output Logs During HTML to PDF Conversion in C#"), modify definition of ouputFile & logFilePath accordingliy:
- Code: Select all
string guid = Guid.NewGuid().ToString();
string outputFile = $"{guid}_HtmlToPDF.pdf";
// Specify the log file path
string logFilePath = $"{guid}_Logs.txt";
- Register Interface in startup as Transient:
- Code: Select all
builder.Services.AddTransient<IPdfConverter, PdfConverter>();
- Create controller with parameterless HttpGet Function, inject interface & call the function.
- Code: Select all
[ApiController]
[Route("[controller]")]
public class HtmlController(IPdfConverter pdfConverter) : ControllerBase
{
[HttpGet]
public async Task<ActionResult> Hello()
{
try
{
pdfConverter.ConvertHtmlToPdf();
return this.Ok();
}
catch(Exception ex) {
return this.StatusCode(500, ex.Message);
}
}
}
- Create a Script which instantly calls this Endpoint 5x
The Result should be that only 2-3 pdfs are generated, while the other 2-3 Log-Files look like the attached File.
I could provide a dockerfile as well in the future for linux but i guess ist the same issue since the Logs from ChromeHtmlConverter.Logger stop at the same time.