StandardPdfFonts.vb
'' 完毕:
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Text
Imports GCTEXT = GrapeCity.Documents.Text
Imports GCDRAW = GrapeCity.Documents.Drawing

'' PDF 规范列出了 14 种应始终可用的标准字体。
'' GcDocs.Pdf 内置了这些字体,并允许您直接使用它们,如本示例所示。
Public Class StandardPdfFonts
    Function CreatePDF(ByVal stream As Stream) As Integer
        Dim doc = New GcPdfDocument()
        Dim g = doc.NewPage().Graphics
        '' 插入点(GcDocs.Pdf的默认分辨率为72dpi,周围使用1英寸边距):
        Const margin = 72
        Dim ip = New PointF(margin, margin)
        Dim tf = New TextFormat() With {.FontSize = 12}
        Dim drawText As Action(Of String, GCTEXT.Font) =
            Sub(tag_ As String, fnt_ As GCTEXT.Font)
                tf.Font = fnt_
                Dim tstr = $"{tag_} ({fnt_.FullFontName}): The quick brown fox jumps over the lazy dog."
                Dim s = g.MeasureString(tstr, tf, doc.PageSize.Width - margin * 2)
                g.DrawString(tstr, tf, New RectangleF(ip, s))
                ip.Y += s.Height * 1.5F
            End Sub
        '' 绘制所有 14 种标准字体的样本:
        drawText("Helvetica", StandardFonts.Helvetica)
        drawText("HelveticaItalic", StandardFonts.HelveticaItalic)
        drawText("HelveticaBold", StandardFonts.HelveticaBold)
        drawText("HelveticaBoldItalic", StandardFonts.HelveticaBoldItalic)
        drawText("Times", StandardFonts.Times)
        drawText("TimesItalic", StandardFonts.TimesItalic)
        drawText("TimesBold", StandardFonts.TimesBold)
        drawText("TimesBoldItalic", StandardFonts.TimesBoldItalic)
        drawText("Courier", StandardFonts.Courier)
        drawText("CourierItalic", StandardFonts.CourierItalic)
        drawText("CourierBold", StandardFonts.CourierBold)
        drawText("CourierBoldItalic", StandardFonts.CourierBoldItalic)
        drawText("Symbol", StandardFonts.Symbol)
        drawText("ZapfDingbats", StandardFonts.ZapfDingbats)
        ''
        '' 完毕:
        doc.Save(stream)
        Return doc.Pages.Count
    End Function
End Class