Hi, I'm using PdfSharpCore with HTMLRendererCore. I want to render pieces of HTML text within an area on the pdf. For that, I have this method:
Code:
protected void HtmlDrawString(ReportProcessDto dto,
XGraphics xGraphics,
double x,
double y,
double width,
double height,
string text,
string font,
string size,
string color,
string alignment = ReportConsts.AlignCenter)
{
using (var container = new HtmlContainer())
{
var pageSize = new XSize(dto.PaperSizeWidth, dto.PaperSizeHeight);
XPoint pointer = new XPoint(x, y);
container.MaxSize = new XSize(width, height);
container.PageSize = pageSize;
container.Location = pointer;
var fontFamily = $"font-family: {font};";
var fontSize = $"font-size: {size}px;";
var fontColor = $"color: {color};";
var cssAlignment = $"text-align: {alignment};";
container.SetHtml($"<div style='{fontFamily} {fontSize} {fontColor} {cssAlignment}'>{text}</div>");
using (var measure = XGraphics.CreateMeasureContext(pageSize, XGraphicsUnit.Point, XPageDirection.Downwards))
{
container.PerformLayout(measure);
}
container.PerformPaint(xGraphics);
}
}
However, it seems that no matter what font family is passed, it always defaults to using what looks to be Arial or Segoe UI. On the contrary, using
Code:
XTextFormatter.DrawString()
method renders texts with the correct font family. For HTML texts however, I'd like to stick to the HTML Renderer if possible.
Is there any reason why this is happening? Does it have something to do with the FontResolver? I tested the GlobalFontSettings.FontResolver to see if it could resolve fonts like Tahoma and Calibri, and it was able to. Any help is much appreciated.