I need to make my document page landscape and I tried to achieve that by using below code. But it is not working. I need to know why it’s not working and how can I achieve that.
foreach (Page page in pdfDocument.Pages)
{
page.PageInfo.IsLandscape = true;
}
Please use the following code example to achieve your requirement. Hope this helps you.
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(MyDir + "input.pdf");
foreach (Page page in doc.Pages)
{
Aspose.Pdf.Rectangle r = page.MediaBox;
double newHeight = r.Width;
double newWidth = r.Height;
double newLLX = r.LLX;
// We must to move page upper in order to compensate changing page size
// (lower edge of the page is 0,0 and information is usually placed from the
// Top of the page. That's why we move lover edge upper on difference between
// Old and new height.
double newLLY = r.LLY + (r.Height - newHeight);
page.MediaBox = new Aspose.Pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight);
// Sometimes we also need to set CropBox (if it was set in original file)
page.CropBox = new Aspose.Pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight);
// Setting Rotation angle of page
page.Rotate = Rotation.None;
}
dataDir = dataDir + "ChangeOrientation_out.pdf";
doc.Save(dataDir);
Further to my previous post, you can change the PDF page size to achieve your requirement as well. Please read the following article. Change PDF Page Size with C#