LinearizedPdf.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

'' Shows how to create a linearized PDF file.
'' Note that while the code below was used to generate the PDF shown in the sample browser,
'' the browser sends a static copy of this file, so that the web server can send it
'' in smaller chunks (all other sample PDFs are generated on the fly).
Public Class LinearizedPdf
    Sub CreatePDF(ByVal stream As Stream)
        '' Number of pages to generate:
        Dim N = 5000
        Dim doc = New GcPdfDocument()
        '' Prep a TextLayout to hold/format the text:
        Dim Page = doc.NewPage()
        Dim tl = Page.Graphics.CreateTextLayout()
        tl.DefaultFormat.Font = StandardFonts.Times
        tl.DefaultFormat.FontSize = 12
        '' Use TextLayout to layout the whole page including margins:
        tl.MaxHeight = Page.Size.Height
        tl.MaxWidth = Page.Size.Width
        tl.MarginAll = 72
        tl.FirstLineIndent = 72 / 2
        '' Generate the document:
        For pageIdx = 0 To N - 1
            '' Note: for the sake of this sample, we do not care if a sample text does not fit on a page.
            tl.Append(Util.LoremIpsum(2))
            tl.PerformLayout(True)
            doc.Pages.Last.Graphics.DrawTextLayout(tl, PointF.Empty)
            If (pageIdx < N - 1) Then
                doc.Pages.Add()
                tl.Clear()
            End If
        Next
        '' To create a linearized PDF we need to specify SaveMode.Linearized when saving the PDF
        doc.Save(stream, SaveMode.Linearized)
    End Sub
End Class