WordCharWrap.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
  6. Imports System.IO
  7. Imports System.Drawing
  8. Imports GrapeCity.Documents.Pdf
  9. Imports GrapeCity.Documents.Text
  10. Imports GrapeCity.Documents.Drawing
  11.  
  12. '' This sample demonstrates the difference between WordWrap And CharWrap
  13. '' text wrapping modes.
  14. Public Class WordCharWrap
  15. Function CreatePDF(ByVal stream As Stream) As Integer
  16. Dim str =
  17. "Lose nothing in your documents! Document Solutions for PDF includes text and paragraph formatting, " +
  18. "special characters, multiple languages, RTL support, vertical and rotated text on all supported platforms."
  19.  
  20. Dim doc = New GcPdfDocument()
  21. Dim page = doc.NewPage()
  22. Dim g = page.Graphics
  23.  
  24. Dim tl = g.CreateTextLayout()
  25. tl.Append(str)
  26. tl.DefaultFormat.Font = StandardFonts.Times
  27. tl.DefaultFormat.FontSize = 12
  28. tl.MaxWidth = 72 * 3
  29.  
  30. tl.WrapMode = WrapMode.WordWrap
  31. tl.PerformLayout(True)
  32.  
  33. Dim dy = tl.Lines(0).Height + 72 / 16
  34. Dim rc = New RectangleF(72, 72 + dy, tl.MaxWidth, 72 * 1.4F)
  35.  
  36. g.DrawString("WrapMode.WordWrap:", tl.DefaultFormat, New PointF(rc.Left, rc.Top - dy))
  37. g.DrawTextLayout(tl, rc.Location)
  38. g.DrawRectangle(rc, Color.CornflowerBlue)
  39.  
  40. rc.Offset(0, 72 * 2)
  41. tl.WrapMode = WrapMode.CharWrap
  42. tl.PerformLayout(False)
  43. g.DrawString("WrapMode.CharWrap:", tl.DefaultFormat, New PointF(rc.Left, rc.Top - dy))
  44. g.DrawTextLayout(tl, rc.Location)
  45. g.DrawRectangle(rc, Color.CornflowerBlue)
  46.  
  47. '' Done
  48. doc.Save(stream)
  49. Return doc.Pages.Count
  50. End Function
  51. End Class
  52.