Page Orientation Swapping Page Size Values in Word Document | Page Width & Height | Landscape Portrait | C# .NET

Hello,

I have an issue with an unintuitive behavior of PageSetup properties. I’m setting PageWidth and PageHeight for a section (where PageWidth > PageHeight) and seems like after setting Orientation to Landscape, those values are swapped. My resulting page is set to Landscape in MS Word settings as expected, but looks like Portrait because of the swapped dimensions. I’d expect that in Landscape orientation, the page width is greater than height, so swapping the dimensions in such case seems a bit surprising. Is this expected to work like this?

Please find the example solution attached. PageOrientation.zip (26.6 KB)

Thanks,
Anna

@acturisaspose,

Please try specifying Width and Height after setting the Orientation of Section to Landscape.

var doc = new Document();
var section = new Section(doc);

section.PageSetup.Orientation = Aspose.Words.Orientation.Landscape;
section.PageSetup.PageWidth = 841.89; //27.9cm
section.PageSetup.PageHeight = 595.28; //21cm

doc.Sections.Add(section);

doc.Save("C:\\Temp\\21.2.docx");

Hi,

Thanks for the response. Yes, I have noticed that setting size after setting the orientation gives me the correct output. Nevertheless, I’d prefer not to depend on the order of properties here. My point is that maybe swapping the values should not happen always, but only when this makes sense for the orientation that is being set?

@acturisaspose,

We have logged this problem in our issue tracking system. Your ticket number is WORDSNET-21778. We will further look into the details of this and will keep you updated here on the status of the linked issue. We apologize for any inconvenience.

@acturisaspose,

Regarding WORDSNET-21778, we have completed the analysis of this issue and concluded to close this issue with “not a bug” status. Please check the following analysis details:

  1. Changing page orientation swaps width and height. This is MS Word’s behavior.
  2. Actually, MS Word does not allow to have page width more than height with portrait mode (the same for landscape and height bigger than width). It changes page orientation automatically. There are even some questions how to prevent it. It seems it depends on MS Word version, maybe MS Word 2003 allows it. But for modern versions you are unable to set page width more than height and have portrait orientation. Even for document with custom modificated section properties, MS Word shows ‘portrait’ mode despite there is ‘landscape’ in the markup.
  3. Another important point is that the Page orientation is more about printing, not about page size itself, despite size depends on it.
  4. Libre office swaps width and height and changes page orientation automatically as well.