Working with Page Rotation
Contents
[
Hide
]
PdfPageEditor class provides the facility to rotate a page.
Rotate page using PageRotations
To rotate pages in document we can use PageRotations.
PageRotations
contains the page number and rotation degree, the key represents the page number, the value of key represents the rotation in degrees.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void RotatePages1()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf();
using (var editor = new Aspose.Pdf.Facades.PdfPageEditor())
{
// Bind PDF document
editor.BindPdf(dataDir + "sample.pdf");
// Specify the page rotation dictionary
editor.PageRotations = new System.Collections.Generic.Dictionary<int, int>
{
{ 1, 90 },
{ 2, 180 },
{ 3, 270 }
};
// Save PDF document
editor.Save(dataDir + "sample-rotate-a.pdf");
}
}
Rotate page using Rotation
We can also use Rotation propety. The rotation must be 0, 90, 180 or 270
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void RotatePages2()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf();
using (var editor = new Aspose.Pdf.Facades.PdfPageEditor())
{
// Bind PDF document
editor.BindPdf(dataDir + "sample.pdf");
// Specify the pages to rotate and the rotation angle
editor.ProcessPages = new int[] { 1, 3 };
editor.Rotation = 90;
// Save PDF document
editor.Save(dataDir + "sample-rotate-a.pdf");
}
}