PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Sun Feb 15, 2026 7:13 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Dec 23, 2025 9:31 am 
Offline

Joined: Tue Dec 23, 2025 9:08 am
Posts: 1
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.


Top
 Profile  
Reply with quote  
PostPosted: Tue Dec 23, 2025 10:04 am 
Offline
PDFsharp Guru
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 1067
Location: CCAA
yxxeratia wrote:
Hi, I'm using PdfSharpCore with HTMLRendererCore.
Both libraries are off-topic here.
Maybe try the support channels for those libraries.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 669 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group