PageSize.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.Common
  8. Imports GrapeCity.Documents.Pdf
  9. Imports GrapeCity.Documents.Text
  10.  
  11. '' Shows how to change page size and orientation in DsPdf.
  12. Public Class PageSize
  13. Sub CreatePDF(ByVal stream As Stream)
  14. Dim in2mm = 72.0F / 25.4F
  15. Dim colorOrig = Color.Red
  16. Dim colorNew = Color.Blue
  17. Dim doc = New GcPdfDocument()
  18. '' The default page size is Letter (8 1/2" x 11") with portrait orientation:
  19. Dim page = doc.NewPage()
  20. Dim sOrigPageInfo = $"Original page size: {page.Size} pts ({page.Size.Width / 72.0F}"" * {page.Size.Height / 72.0F}""),{vbCrLf}" +
  21. $"paper kind: {page.PaperKind}, landscape: {page.Landscape}."
  22. '' Save original page bounds:
  23. Dim rOrig = page.Bounds
  24. '' Change page parameters:
  25. page.Landscape = True
  26. page.PaperKind = PaperKind.A4
  27. Dim sNewPageInfo = $"New page size: {page.Size} pts ({page.Size.Width / 72.0F}"" * {page.Size.Height / 72.0F}""),{vbCrLf}" +
  28. $"paper kind: {page.PaperKind}, landscape: {page.Landscape}."
  29. '' New page bounds:
  30. Dim rNew = page.Bounds
  31. '' Draw original and new page bounds:
  32. page.Graphics.DrawRectangle(rOrig, colorOrig, 6)
  33. page.Graphics.DrawRectangle(rNew, colorNew, 6)
  34. '' Draw original and new page infos:
  35. Dim tf = New TextFormat() With {
  36. .Font = StandardFonts.Times,
  37. .FontSize = 14,
  38. .ForeColor = colorOrig
  39. }
  40. page.Graphics.DrawString(sOrigPageInfo, tf, New PointF(72, 72))
  41. tf.ForeColor = colorNew
  42. page.Graphics.DrawString(sNewPageInfo, tf, New PointF(72, 72 * 2))
  43. '' Done:
  44. doc.Save(stream)
  45. End Sub
  46. End Class
  47.