LargeDocument2.vb
'' 完毕:
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Text
Imports GCTEXT = GrapeCity.Documents.Text
Imports GCDRAW = GrapeCity.Documents.Drawing

'' 生成一个大的 PDF。
'' 此示例​​与StartEndDoc相同,但不使用StartDoc/EndDoc方法。
Public Class LargeDocument2
    Function CreatePDF(ByVal stream As Stream) As Integer
        '' 生成的页数:
        Const N = Util.LargeDocumentIterations
        Dim start = Util.TimeNow()
        Dim doc = New GcPdfDocument()
        '' 准备一个 TextLayout 来保存/格式化文本:
        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
        '' 生成文档:
        For pageIdx = 1 To N
            tl.Append(Util.LoremIpsum(1))
            tl.PerformLayout(True)
            doc.NewPage().Graphics.DrawTextLayout(tl, PointF.Empty)
            tl.Clear()
        Next
        '' 插入标题页(如果使用 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("大文档" + vbLf + "{0} 页 Lorem Ipsum" + vbLf + vbLf, N), tf0)
        Dim tf1 = New TextFormat(tf0) With {.FontSize = 14, .FontItalic = True}
        tl.Append(String.Format("于 {0} 上的 {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)
        '' 完毕:
        doc.Save(stream)
        Return doc.Pages.Count
    End Function
End Class