Search code examples
c#pdfsharp

Formatting text using PDFsharp


I want to apply style to

string "Helloword"

and have style properties

like fontFamily='Verdana', fontStyle='bold', FontSize='12', textDecoration='underline', textAlign='center', fontColor='#FF0000', x=100 and y=100.

I want to display this string in PDF using PDFsharp. can anyone suggest me how to do that?

I'm using XFont and XGraphics.DrawString method but I'm not able to apply all above styles.


Solution

  • The string is slightly incorrect, but I hope all other requirements are met:

    // Create a font
    XFont font = new XFont("Verdana", 12, XFontStyle.Bold | XFontStyle.Underline);
    
    // Draw the text
    gfx.DrawString("Hello, World!", font, new XSolidBrush(XColor.FromArgb(255, 0, 0)),
      100, 100,
      XStringFormats.Center);