StandardPdfFonts.vb
  1. ''
  2. '' This code is part of Document Solutions for PDF demos.
  3. '' Copyright (c) MESCIUS inc. All rights reserved.
  4. ''
  5. Imports System.IO
  6. Imports System.Drawing
  7. Imports GrapeCity.Documents.Pdf
  8. Imports GrapeCity.Documents.Text
  9. Imports GCTEXT = GrapeCity.Documents.Text
  10. Imports GCDRAW = GrapeCity.Documents.Drawing
  11.  
  12. '' PDF specification lists 14 standard fonts that should always be available.
  13. '' DsPdf has those fonts built in, and allows using them directly as this sample demonstrates.
  14. Public Class StandardPdfFonts
  15. Function CreatePDF(ByVal stream As Stream) As Integer
  16. Dim doc = New GcPdfDocument()
  17. Dim g = doc.NewPage().Graphics
  18. '' Insertion point (DsPdf's default resolution is 72dpi, use 1" margins all around):
  19. Const margin = 72
  20. Dim ip = New PointF(margin, margin)
  21. Dim tf = New TextFormat() With {.FontSize = 12}
  22. Dim drawText As Action(Of String, GCTEXT.Font) =
  23. Sub(tag_ As String, fnt_ As GCTEXT.Font)
  24. tf.Font = fnt_
  25. Dim tstr = $"{tag_} ({fnt_.FullFontName}): The quick brown fox jumps over the lazy dog."
  26. Dim s = g.MeasureString(tstr, tf, doc.PageSize.Width - margin * 2)
  27. g.DrawString(tstr, tf, New RectangleF(ip, s))
  28. ip.Y += s.Height * 1.5F
  29. End Sub
  30. '' Draw samples of all 14 standard fonts:
  31. drawText("Helvetica", StandardFonts.Helvetica)
  32. drawText("HelveticaItalic", StandardFonts.HelveticaItalic)
  33. drawText("HelveticaBold", StandardFonts.HelveticaBold)
  34. drawText("HelveticaBoldItalic", StandardFonts.HelveticaBoldItalic)
  35. drawText("Times", StandardFonts.Times)
  36. drawText("TimesItalic", StandardFonts.TimesItalic)
  37. drawText("TimesBold", StandardFonts.TimesBold)
  38. drawText("TimesBoldItalic", StandardFonts.TimesBoldItalic)
  39. drawText("Courier", StandardFonts.Courier)
  40. drawText("CourierItalic", StandardFonts.CourierItalic)
  41. drawText("CourierBold", StandardFonts.CourierBold)
  42. drawText("CourierBoldItalic", StandardFonts.CourierBoldItalic)
  43. drawText("Symbol", StandardFonts.Symbol)
  44. drawText("ZapfDingbats", StandardFonts.ZapfDingbats)
  45. ''
  46. '' Done:
  47. doc.Save(stream)
  48. Return doc.Pages.Count
  49. End Function
  50. End Class
  51.