LinearizedPdf.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.  
  10. '' Shows how to create a linearized PDF file.
  11. '' Note that while the code below was used to generate the PDF shown in the sample browser,
  12. '' the browser sends a static copy of this file, so that the web server can send it
  13. '' in smaller chunks (all other sample PDFs are generated on the fly).
  14. Public Class LinearizedPdf
  15. Sub CreatePDF(ByVal stream As Stream)
  16. '' Number of pages to generate:
  17. Dim N = 5000
  18. Dim doc = New GcPdfDocument()
  19. '' Prep a TextLayout to hold/format the text:
  20. Dim Page = doc.NewPage()
  21. Dim tl = Page.Graphics.CreateTextLayout()
  22. tl.DefaultFormat.Font = StandardFonts.Times
  23. tl.DefaultFormat.FontSize = 12
  24. '' Use TextLayout to layout the whole page including margins:
  25. tl.MaxHeight = Page.Size.Height
  26. tl.MaxWidth = Page.Size.Width
  27. tl.MarginAll = 72
  28. tl.FirstLineIndent = 72 / 2
  29. '' Generate the document:
  30. For pageIdx = 0 To N - 1
  31. '' Note: for the sake of this sample, we do not care if a sample text does not fit on a page.
  32. tl.Append(Util.LoremIpsum(2))
  33. tl.PerformLayout(True)
  34. doc.Pages.Last.Graphics.DrawTextLayout(tl, PointF.Empty)
  35. If (pageIdx < N - 1) Then
  36. doc.Pages.Add()
  37. tl.Clear()
  38. End If
  39. Next
  40. '' To create a linearized PDF we need to specify SaveMode.Linearized when saving the PDF
  41. doc.Save(stream, SaveMode.Linearized)
  42. End Sub
  43. End Class
  44.