PageSize.vb
  1. '' 完毕:
  2. Imports System.IO
  3. Imports System.Drawing
  4. Imports GrapeCity.Documents.Common
  5. Imports GrapeCity.Documents.Pdf
  6. Imports GrapeCity.Documents.Text
  7.  
  8. '' 演示如何在 GcDocs.Pdf 中更改页面大小和方向。
  9. Public Class PageSize
  10. Sub CreatePDF(ByVal stream As Stream)
  11. Dim in2mm = 72.0F / 25.4F
  12. Dim colorOrig = Color.Red
  13. Dim colorNew = Color.Blue
  14. Dim doc = New GcPdfDocument()
  15. '' 默认页面尺寸为 Letter (8 1/2" x 11"),纵向:
  16. Dim page = doc.NewPage()
  17. Dim sOrigPageInfo = $"Original page size: {page.Size} pts ({page.Size.Width / 72.0F}"" * {page.Size.Height / 72.0F}""),{vbCrLf}" +
  18. $"paper kind: {page.PaperKind}, landscape: {page.Landscape}."
  19. '' 保存原始页面边界:
  20. Dim rOrig = page.Bounds
  21. '' 更改页面参数:
  22. page.Landscape = True
  23. page.PaperKind = PaperKind.A4
  24. Dim sNewPageInfo = $"New page size: {page.Size} pts ({page.Size.Width / 72.0F}"" * {page.Size.Height / 72.0F}""),{vbCrLf}" +
  25. $"paper kind: {page.PaperKind}, landscape: {page.Landscape}."
  26. '' 新页面边界:
  27. Dim rNew = page.Bounds
  28. '' 绘制原始页面边界和新页面边界:
  29. page.Graphics.DrawRectangle(rOrig, colorOrig, 6)
  30. page.Graphics.DrawRectangle(rNew, colorNew, 6)
  31. '' 绘制原始和新的页面信息:
  32. Dim tf = New TextFormat() With {
  33. .Font = StandardFonts.Times,
  34. .FontSize = 14,
  35. .ForeColor = colorOrig
  36. }
  37. page.Graphics.DrawString(sOrigPageInfo, tf, New PointF(72, 72))
  38. tf.ForeColor = colorNew
  39. page.Graphics.DrawString(sNewPageInfo, tf, New PointF(72, 72 * 2))
  40. '' 完毕:
  41. doc.Save(stream)
  42. End Sub
  43. End Class
  44.