'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.TextImports GCTEXT = GrapeCity.Documents.Text '' Demonstrates the basics of character formatting in DsPdf.'' '' Character formatting in Document Solutions for PDF is done via GrapeCity.Documents.Text.TextFormat class.'' An instance of that class with the required formatting options'' is passed to most text rendering methods available in DsPdf (e.g. DrawString).'' Rendering text with different character formatting in the same paragraph'' is done by using TextLayout/DrawTextLayout.'' See also TextRendering, MultiFormattedText, ParagraphAlign,'' ParagraphFormatting, TextAlign.PublicClassCharacterFormattingFunctionCreatePDF(ByVal stream AsStream) AsIntegerDim doc = NewGcPdfDocument()Dim page = doc.NewPage()Dim g = page.GraphicsConstInch = 72.0F, vStep = Inch / 2Dim ip = NewPointF(Inch, Inch) '' 1. The only mandatory property that must be set on a TextFormat is Font:Dim tf = NewTextFormat() With {.Font = StandardFonts.Times} g.DrawString("1. The only mandatory property that must always be set on a TextFormat is Font." +"Even FontSize is optional, and defaults to 12pts.", tf, ip) ip.Y += vStep * 2 '' 2. Standard font properties are available: tf.Underline = True tf.Strikethrough = True tf.FontSize = 10 g.DrawString("2. Standard properties are available, here we turn Underline and Strikethrough on, and set FontSize to 10.", tf, ip) ip.Y += vStep '' 3. TextFormat.FontStyle allows emulating bold and/or italic styles '' using a regular font (see also BoldItalicEmulation): tf.Underline = tf.Strikethrough = False tf.FontStyle = GCTEXT.FontStyle.BoldItalic tf.FontSize = 12 g.DrawString("3. Using TextFormat.FontStyle.BoldItalic to emulate bold italic style.", tf, ip) ip.Y += vStep '' 4. Other properties include foreground and background colors: tf.FontStyle = GCTEXT.FontStyle.Regular tf.ForeColor = Color.DarkSlateBlue tf.BackColor = Color.PaleGreen g.DrawString("4. Using TextFormat.ForeColor and TextFormat.BackColor to colorize the text.", tf, ip) ip.Y += vStep '' 5. Different text formats may be mixed in the same paragraph.'' For that, TextLayout and GcPdfGraphics.DrawTextLayout must be used:Dim tl = g.CreateTextLayout() tl.Append("5. Different text formats can be easily mixed in the same paragraph",NewTextFormat() With {.Font = StandardFonts.Times}) tl.Append("when the paragraph is built with TextLayout",NewTextFormat() With {.Font = StandardFonts.TimesBold, .BackColor = Color.PaleTurquoise}) tl.Append("as this sample paragraph shows.",NewTextFormat() With {.Font = StandardFonts.HelveticaBoldItalic, .ForeColor = Color.DarkOrange}) tl.Append("Various other options are available on TextFormat, including",NewTextFormat() With {.Font = StandardFonts.Times, .ForeColor = Color.DarkSlateBlue}) tl.Append(" GlyphAdvanceFactor ",NewTextFormat() With {.Font = StandardFonts.TimesBoldItalic, .Underline = True}) tl.Append(" (spreading glyphs out ",NewTextFormat() With {.Font = StandardFonts.Times, .GlyphAdvanceFactor = 1.5F, .ForeColor = Color.BlueViolet}) tl.Append("or putting them closer together), ",NewTextFormat() With {.Font = StandardFonts.Times, .GlyphAdvanceFactor = 0.8F, .ForeColor = Color.BlueViolet}) tl.Append("TransverseOffset",NewTextFormat() With {.Font = StandardFonts.TimesBoldItalic, .Underline = True}) tl.Append(" (lowering the glyphs below the base line, ",NewTextFormat() With {.Font = StandardFonts.Times, .TransverseOffset = -5, .ForeColor = Color.MediumVioletRed}) tl.Append("or raising them above it)",NewTextFormat() With {.Font = StandardFonts.Times, .TransverseOffset = 5, .ForeColor = Color.MediumVioletRed}) tl.Append(" and more (for example, specific fonts' features are accessible via TextFormat.FontFeatures).",NewTextFormat() With {.Font = StandardFonts.Times, .FontFeatures = NewFontFeature() {NewFontFeature(FeatureTag.clig)}}) '' For this sample, we just set the max width of the text layout,'' in a real app you would probably set at least the MaxHeight too: tl.MaxWidth = page.Size.Width - Inch * 2 tl.PerformLayout(True) g.DrawTextLayout(tl, ip)'''' Done: doc.Save(stream)Return doc.Pages.CountEndFunctionEndClass