When setting PDF.Page.IsLandscape = true- should it not update the width and height?

Dim myReport As New Aspose.Pdf.Document

Dim myPage As Aspose.Pdf.Page = myReport.Pages.Add()

' height = 842
' width = 595

Dim width As Double = myPage.PageInfo.Width
Dim height As Double = myPage.PageInfo.Height

myPage.PageInfo.IsLandscape = True

' Shouldn't the width and height be swapped?

' height = 595
' width = 842
Dim width2 As Double = myPage.PageInfo.Width
Dim height2 As Double = myPage.PageInfo.Height

MsgBox("width:height before: " + width.ToString() + ":" + height.ToString() + vbCrLf + "width:height after " + width2.ToString() + ":" + height2.ToString())

myReport.Save("Test.pdf")

Hi Cameron,

Thanks for contacting support.

Currently, the PageInfo.IsLandscape property has some issues while changing page orientation. However, in order to resolve this issue, please try using the following code lines.

[VB.NET]

Dim w As Double = myReport.Pages(1).Rect.Width
Dim h As Double = myReport.Pages(1).Rect.Height
myReport.Pages(1).MediaBox = New Rectangle(0, 0, h * h / w, h)
myReport.Pages(1).CropBox = New Rectangle(0, 0, h * h / w, h)
Unfortunately that didn't work for me. Below is the solution that I came up with

The reason why it wasn't working is because Pdf.HorizontalAlignment and Pdf.VerticleAlignment relies on the width and the height of the page, as found in PageInfo.Width and Height.


Dim file As New MemoryStream

Dim myReport As New Aspose.Pdf.Document

Dim myPage As Aspose.Pdf.Page = myReport.Pages.Add()

' height = 842
' width = 595

Dim width As Double = myPage.PageInfo.Width
Dim height As Double = myPage.PageInfo.Height

'myPage.PageInfo.IsLandscape = True <-- This is now simulated with the setPageSize.

myPage.SetPageSize(myPage.PageInfo.Height, myPage.PageInfo.Width)

' Shouldn't the width and height be swapped?

' height = 595
' width = 842
Dim width2 As Double = myPage.PageInfo.Width
Dim height2 As Double = myPage.PageInfo.Height

MsgBox("width:height before: " + width.ToString() + ":" + height.ToString() + vbCrLf + "width:height after " + width2.ToString() + ":" + height2.ToString())

myReport.Save("Test.pdf")

Button1.Text = "done"

Hi Cameron,


Thanks for your feedback. It is good to know that you have managed to accomplish your requirement. You are right when you are generating a new PDF document PageInfo Width and Height property is used for setting Page dimensions. However for an existing PDF document you can used SetPageSIze() method.

We are sorry for the inconvenience caused.

Best Regards,