LargeDocument2.vb
''
'' This code is part of Document Solutions for PDF demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Text
Imports GCTEXT = GrapeCity.Documents.Text
Imports GCDRAW = GrapeCity.Documents.Drawing

'' Generates a large PDF.
'' This sample is identical to StartEndDoc, but does not use the StartDoc/EndDoc method.
Public Class LargeDocument2
    Function CreatePDF(ByVal stream As Stream) As Integer
        '' Number of pages to generate:
        Const N = Util.LargeDocumentIterations
        Dim start = Util.TimeNow()
        Dim doc = New GcPdfDocument()
        '' Prep a TextLayout to hold/format the text:
        Dim tl = New TextLayout(72) With {
            .MaxWidth = doc.PageSize.Width,
            .MaxHeight = doc.PageSize.Height,
            .MarginAll = 72,
            .FirstLineIndent = 36
        }
        tl.DefaultFormat.Font = StandardFonts.Times
        tl.DefaultFormat.FontSize = 12
        '' Generate the document:
        For pageIdx = 1 To N
            tl.Append(Util.LoremIpsum(1))
            tl.PerformLayout(True)
            doc.NewPage().Graphics.DrawTextLayout(tl, PointF.Empty)
            tl.Clear()
        Next
        '' Insert a title page (cannot be done if using StartDoc/EndDoc):
        tl.FirstLineIndent = 0
        Dim fnt = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "yumin.ttf"))
        Dim tf0 = New TextFormat() With {.FontSize = 24, .FontBold = True, .Font = fnt}
        tl.Append(String.Format("Large Document" + vbLf + "{0} Pages of Lorem Ipsum" + vbLf + vbLf, N), tf0)
        Dim tf1 = New TextFormat(tf0) With {.FontSize = 14, .FontItalic = True}
        tl.Append(String.Format("Generated on {0} in {1:m\m\ s\s\ fff\m\s}.", Util.TimeNow().ToString("R"), Util.TimeNow() - start), tf1)
        tl.TextAlignment = TextAlignment.Center
        tl.PerformLayout(True)
        doc.Pages.Insert(0).Graphics.DrawTextLayout(tl, PointF.Empty)
        '' Done:
        doc.Save(stream)
        Return doc.Pages.Count
    End Function
End Class