LargeDocument2.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. '' Generates a large PDF.
  13. '' This sample is identical to StartEndDoc, but does not use the StartDoc/EndDoc method.
  14. Public Class LargeDocument2
  15. Function CreatePDF(ByVal stream As Stream) As Integer
  16. '' Number of pages to generate:
  17. Const N = Util.LargeDocumentIterations
  18. Dim start = Util.TimeNow()
  19. Dim doc = New GcPdfDocument()
  20. '' Prep a TextLayout to hold/format the text:
  21. Dim tl = New TextLayout(72) With {
  22. .MaxWidth = doc.PageSize.Width,
  23. .MaxHeight = doc.PageSize.Height,
  24. .MarginAll = 72,
  25. .FirstLineIndent = 36
  26. }
  27. tl.DefaultFormat.Font = StandardFonts.Times
  28. tl.DefaultFormat.FontSize = 12
  29. '' Generate the document:
  30. For pageIdx = 1 To N
  31. tl.Append(Util.LoremIpsum(1))
  32. tl.PerformLayout(True)
  33. doc.NewPage().Graphics.DrawTextLayout(tl, PointF.Empty)
  34. tl.Clear()
  35. Next
  36. '' Insert a title page (cannot be done if using StartDoc/EndDoc):
  37. tl.FirstLineIndent = 0
  38. Dim fnt = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "yumin.ttf"))
  39. Dim tf0 = New TextFormat() With {.FontSize = 24, .FontBold = True, .Font = fnt}
  40. tl.Append(String.Format("Large Document" + vbLf + "{0} Pages of Lorem Ipsum" + vbLf + vbLf, N), tf0)
  41. Dim tf1 = New TextFormat(tf0) With {.FontSize = 14, .FontItalic = True}
  42. tl.Append(String.Format("Generated on {0} in {1:m\m\ s\s\ fff\m\s}.", Util.TimeNow().ToString("R"), Util.TimeNow() - start), tf1)
  43. tl.TextAlignment = TextAlignment.Center
  44. tl.PerformLayout(True)
  45. doc.Pages.Insert(0).Graphics.DrawTextLayout(tl, PointF.Empty)
  46. '' Done:
  47. doc.Save(stream)
  48. Return doc.Pages.Count
  49. End Function
  50. End Class
  51.