Skip to content

Rotate PDF pages in C#

Since 1.0View as Markdown

Turn pages clockwise by 90, 180 or 270 degrees.

Call Rotate on a page with a multiple of 90. The rotation adds to the page’s current one and viewers apply it when they display the page; the content itself is not rewritten. Rotation reads the result: 0, 90, 180 or 270.

recipe-rotate-pdf-pages.cs
#:package PdfNetStack@1.2.0
using PdfNetStack;
PdfDocument doc = PdfDocument.Open("report.pdf");
doc.Pages[0].Rotate(90); // clockwise, a multiple of 90
foreach (PdfPage page in doc.Pages.Skip(1))
{
page.Rotate(180);
}
doc.Save("report-rotated.pdf");
Console.WriteLine(string.Join(", ", doc.Pages.Select(p => p.Rotation)));
Terminal window
dotnet add package PdfNetStack