Search code examples
c#pdfsharp

PDF Sharp setting font styles


I have a font dialog to let user pick a font name, font size and also possibly a font style.

but this code doesn't work

XFont myFont = new XFont(txtP.Font.Name, txtP.Font.Size, txtP.Font.Style);

Error is: Error 2 Argument 3: cannot convert from 'System.Drawing.FontStyle' to 'PdfSharp.Drawing.XFontStyle' / Error 1 The best overloaded method match for 'PdfSharp.Drawing.XFont.XFont(string, double, PdfSharp.Drawing.XFontStyle)' has some invalid arguments

is there a workaround on this? I would really like to let users choose Font Style also not just name and size.


Solution

  • I solved the issue by

    XFont myFont = new XFont(txtP.Font.Name, txtP.Font.Size, (PdfSharp.Drawing.XFontStyle)fontStyle);