Articles in this section
Category / Section

How to draw different font style in the same line of PDF in WinRT?

4 mins read

The PdfTextElement class can be used to draw the text using different font styles in the same line, by getting the bounds of the preceding text. Please find the sample and code snippet below.

C#:

float nextText = 0;
private void Button_Click(object sender, RoutedEventArgs e)
{
    // Creates a new PDF document
    PdfDocument doc = new PdfDocument();
    // Add a page
    PdfPage page = doc.Pages.Add();
    // Create PDF graphics for the page
    PdfGraphics g = page.Graphics;
    PdfBrush brush = PdfBrushes.Black;
    PdfFont boldFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 12, PdfFontStyle.Bold);
    PdfFont regularFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 12, PdfFontStyle.Regular);
    PdfFont italicFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 12, PdfFontStyle.Italic);
    PdfLayoutResult result;
    result = AddString("Hello World ", page, 0, brush, boldFont);
    result = AddString("Hello World ", page, result.Bounds.Width, brush, regularFont);
    result = AddString("Hello World ", page, result.Bounds.Width, brush, italicFont);
}
private PdfLayoutResult AddString(string note, PdfPage newPage, float xPosition, PdfBrush brush, PdfFont font)
{
    float SpacValue = 10.0f;
    nextText = nextText + (xPosition + SpacValue);
    // Rendering Text
    PdfTextElement richTextElement = new PdfTextElement(note, font, brush);
    // Draws String
    PdfLayoutResult result = richTextElement.Draw(newPage, new RectangleF(nextText, 0, 0, 0));
    return result;
}

 

Sample Link:

https://www.syncfusion.com/downloads/support/forum/118609/ze/SinlgeLineText-1228246529

 

Note:

Starting with v16.2.0.x, if you reference Syncfusion® assemblies from a trial setup or from the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.

 

Conclusion

I hope you enjoyed learning about how to draw different font style in the same line of PDF in WinRT.

You can refer to our WinForms PDF’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms PDF documentation to understand how to present and manipulate data.

For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms PDF and other WinForms components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please  to leave a comment
Access denied
Access denied