'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.Text '' Shows how to use different text formats (fonts, colors) in a single paragraph.PublicClassMultiFormattedTextFunctionCreatePDF(ByVal stream AsStream) AsInteger'' Function to generate sample text quoting its formatting options:Dim makeSampleText As Func(OfTextFormat, String) =Function(ByVal tf_)Dim boldItalic = String.EmptyIf tf_.Font.FontBold Then boldItalic = "bold "EndIfIf tf_.Font.FontItalic Then boldItalic += "italic "EndIfIf boldItalic = String.EmptyThen boldItalic = "normal "EndIfReturn$"This is {boldItalic}text drawn using font '{tf_.Font.FullFontName}', font size {tf_.FontSize} points, " +$"text color {tf_.ForeColor}, background color {tf_.BackColor}. "EndFunction '' Font names:Constserif = "noto serif"Constsans = "noto sans"'' Create document and text layout:Dim doc = NewGcPdfDocument()Dim page = doc.NewPage()Dim g = page.GraphicsDim tl = g.CreateTextLayout()'' Use TextLayout to layout the whole page and maintain margins: tl.MaxHeight = page.Size.Height tl.MaxWidth = page.Size.Width tl.MarginAll = 72'' Get some fonts:Dim fc = NewFontCollection() fc.RegisterDirectory(Path.Combine("Resources", "Fonts"))Dim fTimes = fc.FindFamilyName(serif, False, False)Dim fTimesBold = fc.FindFamilyName(serif, True, False)Dim fTimesItalic = fc.FindFamilyName(serif, False, True)Dim fTimesBoldItalic = fc.FindFamilyName(serif, True, True)Dim fArial = fc.FindFamilyName(sans, False, False)'' Add text to TextLayout using different fonts and font sizes:Dim tf = NewTextFormat() With {.Font = fTimes, .FontSize = 12} tl.Append(makeSampleText(tf), tf) tf.Font = fTimesBold tf.FontSize += 2 tl.Append(makeSampleText(tf), tf) tf.Font = fTimesItalic tf.FontSize += 2 tl.Append(makeSampleText(tf), tf) tf.Font = fTimesBoldItalic tf.FontSize += 2 tl.Append(makeSampleText(tf), tf) tf.Font = fArial tf.FontSize += 2 tl.Append(makeSampleText(tf), tf)'' Add text with different foreground and background colors: tf.Font = fTimesBold tf.ForeColor = Color.Tomato tl.Append(makeSampleText(tf), tf) tf.Font = fTimesBoldItalic tf.FontSize = 16 tf.ForeColor = Color.SlateBlue tf.BackColor = Color.Orange tl.Append(makeSampleText(tf), tf)'' Finish with plain black on transparent again: tl.Append("The end.", NewTextFormat() With {.Font = fTimes, .FontSize = 14})'' Layout and draw text: tl.PerformLayout(True) g.DrawTextLayout(tl, PointF.Empty)'''' Done: doc.Save(stream)Return doc.Pages.CountEndFunctionEndClass