I've just run into exactly the same problem with v1.31.1789.0. My PDF page is 1460x475mm, with a rotation of 90. If I open it with PDFSharp and save it without making any changes, the page size has changed to 475x1460mm with a rotation of 90, which cuts off the right-hand side of the document.
I think the problem is in PdfSharp.Pdf\PdfPage.cs, line 166:
Code:
// THHO: MediaBox is always in Portrait mode (see Height, Width)
/*if (this.orientation == PageOrientation.Portrait)*/
MediaBox = new PdfRectangle(0, 0, size.Width, size.Height);
/*else
MediaBox = new PdfRectangle(0, 0, size.Height, size.Width);*/
In v1.2, this was:
Code:
if (this.orientation == PageOrientation.Portrait)
MediaBox = new PdfRectangle(0, 0, size.Width, size.Height);
else
MediaBox = new PdfRectangle(0, 0, size.Height, size.Width);
The hacky workaround I've used is to call this function after loading any document:
Code:
private static void HackPageRotation([NotNull] PdfDocument document)
{
for (int index = 0; index < document.PageCount; index++)
{
var page = document.Pages[index];
if (PageOrientation.Landscape == page.Orientation)
{
var value = page.MediaBox;
var size = new XSize(value.Height, value.Width);
page.MediaBox = new PdfRectangle(value.Location, size);
}
}
}