I am currently using the HtmlToPdfConverter to convert HTML to an image. Every time the image comes out the background is always black.
The code that I am using is below:
public class HtmlConverterService : IHtmlConverter
{
public byte[] ConvertToByteArray(string html)
{
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
WebKitConverterSettings settings = new WebKitConverterSettings();
settings.WebKitPath = GetQtBinaries();
settings.BackgroundColor = Color.White;
settings.HtmlEncoding = Encoding.UTF8;
settings.WebKitViewPort = new Size();
htmlConverter.ConverterSettings = settings;
Image document = htmlConverter.ConvertToImage(html, "");
return document.ImageData;
}
public string ConvertToBase64(string html)
{
return "data:image/png;base64," + Convert.ToBase64String(ConvertToByteArray(html));
}
private string GetQtBinaries()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return Path.Combine("QtBinaries", "QtBinariesWindows");
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
return Path.Combine("QtBinaries", "QtBinariesLinux");
return Path.Combine("QtBinaries", "QtBinariesMac");
}
}