| PDFsharp & MigraDoc Forum https://forum.pdfsharp.net/ |
|
| Issue with font family when using html renderer https://forum.pdfsharp.net/viewtopic.php?f=2&t=4911 |
Page 1 of 1 |
| Author: | yxxeratia [ Tue Dec 23, 2025 9:31 am ] |
| Post subject: | Issue with font family when using html renderer |
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. |
|
| Author: | TH-Soft [ Tue Dec 23, 2025 10:04 am ] |
| Post subject: | Re: Issue with font family when using html renderer |
yxxeratia wrote: Hi, I'm using PdfSharpCore with HTMLRendererCore. Both libraries are off-topic here.Maybe try the support channels for those libraries. |
|
| Page 1 of 1 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|