We have a static method that returns pdf bytes but there is uncertain times the pdf it generates is blank/distorted. Trying to figure out if an instance of an html to PDF generator being inside a static method causes the output to fail by not being able to generate the expected content in the pdf.
Sample:
public class EvoPDFUtility
{
public static byte[] ConvertHtmlToPdf(string html)
{
var htmlToPdfGenerator = new EvoPDF();
return htmlToPdfGenerator.Convert(html);
}
}
Is the instance inside the static method becomes shared to and the same everytime the static method is called?
CodePudding user response:
No, htmpToPdfGenerator
has local scope.
It is instantiated separately every time the static method is called and eligible for garbage collection as soon as that method exits.
Since each invocation of the static method references only a locally-scoped variable, the method is also thread safe.
CodePudding user response:
Eric is right. It's not because it's a static function. It's more likely:
- Your HTML/CSS
- Fonts
- Possible image issues
Does it have issues generating the PDF several times against the same (good) HTML?