ParagraphFormatting.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 GrapeCity.Documents.Drawing
  10.  
  11. '' This sample demonstrates the most basic paragraph formatting options:
  12. '' - first line indent
  13. '' - line spacing.
  14. Public Class ParagraphFormatting
  15. Function CreatePDF(ByVal stream As Stream) As Integer
  16.  
  17. Dim makePara As Func(Of String) =
  18. Function()
  19. Return Util.LoremIpsum(1, 5, 10, 15, 30)
  20. End Function
  21.  
  22. Dim doc = New GcPdfDocument()
  23. Dim g = doc.NewPage().Graphics
  24. '' Using Graphics.CreateTextLayout() ensures that TextLayout's resolution
  25. '' is set to the same value as that of the graphics (which is 72 dpi by default):
  26. Dim tl = g.CreateTextLayout()
  27. '' Default font:
  28. tl.DefaultFormat.Font = StandardFonts.Times
  29. tl.DefaultFormat.FontSize = 12
  30. '' Set TextLayout to the whole page:
  31. tl.MaxWidth = doc.PageSize.Width
  32. tl.MaxHeight = doc.PageSize.Height
  33. '' ...and have it manage the page margins (1" all around):
  34. tl.MarginAll = tl.Resolution
  35. '' First line offset 1/2":
  36. tl.FirstLineIndent = 72 / 2
  37. '' 1.5 line spacing:
  38. tl.LineSpacingScaleFactor = 1.5F
  39. ''
  40. tl.Append(makePara())
  41. tl.PerformLayout(True)
  42. '' Render text at (0,0) (margins are added by TextLayout):
  43. g.DrawTextLayout(tl, PointF.Empty)
  44. ''
  45. '' Done:
  46. doc.Save(stream)
  47. Return doc.Pages.Count
  48. End Function
  49. End Class
  50.