DEV Community

IronSoftware
IronSoftware

Posted on

PDF Page Orientation and Rotation in C# (Developer Guide)

Page orientation determines whether a PDF displays in portrait or landscape. Rotation corrects pages that were scanned upside down or sideways. Both are common requirements when processing PDFs programmatically.

using IronPdf;
// Install via NuGet: Install-Package IronPdf

var renderer = new [ChromePdfRenderer](https://ironpdf.com/blog/videos/how-to-render-webgl-sites-to-pdf-in-csharp-ironpdf/)();
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape;

var pdf = renderer.RenderHtmlAsPdf("<h1>Wide Report</h1><p>Landscape content...</p>");
pdf.SaveAs("landscape-report.pdf");
Enter fullscreen mode Exit fullscreen mode

IronPDF handles orientation during creation and rotation for existing documents.

What's the Difference Between Orientation and Rotation?

Concept When Applied Use Case
Orientation During PDF creation Set landscape/portrait for new PDFs
Rotation On existing PDFs Fix scanned pages, correct viewing angle

Orientation is a rendering option. Rotation modifies existing pages.

How Do I Set Page Orientation?

Set orientation when generating PDFs from HTML:

using IronPdf;
// Install via NuGet: Install-Package IronPdf

var renderer = new ChromePdfRenderer();

// Portrait (default)
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Portrait;

// Landscape for wide content
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape;

var html = @"
<html>
<body>
    <h1>Financial Dashboard</h1>
    <table style='width:100%;'>
        <!-- Wide table that fits better in landscape -->
    </table>
</body>
</html>";

var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("dashboard.pdf");
Enter fullscreen mode Exit fullscreen mode

Landscape works best for wide tables, charts, and dashboards.

How Do I Rotate Existing PDF Pages?

Rotate pages in 90-degree increments:

using IronPdf;
// Install via NuGet: Install-Package IronPdf

var pdf = PdfDocument.FromFile("scanned-document.pdf");

// Rotate all pages 90 degrees clockwise
pdf.SetAllPageRotations(PdfPageRotation.Clockwise90);

pdf.SaveAs("rotated-document.pdf");
Enter fullscreen mode Exit fullscreen mode

Rotation options:

  • PdfPageRotation.None — 0° (no rotation)
  • PdfPageRotation.Clockwise90 — 90° clockwise
  • PdfPageRotation.Clockwise180 — 180° (upside down)
  • PdfPageRotation.Clockwise270 — 270° clockwise (same as 90° counter-clockwise)

How Do I Rotate Specific Pages?

Target individual pages for rotation:

using IronPdf;
// Install via NuGet: Install-Package IronPdf

var pdf = PdfDocument.FromFile("mixed-orientation.pdf");

// Rotate just the first page
pdf.SetPageRotation(0, PdfPageRotation.Clockwise90);

// Rotate multiple specific pages
pdf.SetPageRotations(new[] { 2, 4, 6 }, PdfPageRotation.Clockwise180);

pdf.SaveAs("selectively-rotated.pdf");
Enter fullscreen mode Exit fullscreen mode

Page indices are zero-based.

How Do I Check Current Page Rotation?

Read existing rotation values:

using IronPdf;
// Install via NuGet: Install-Package IronPdf

var pdf = PdfDocument.FromFile("document.pdf");

for (int i = 0; i < pdf.PageCount; i++)
{
    var rotation = pdf.GetPageRotation(i);
    Console.WriteLine($"Page {i + 1}: {rotation}");
}
Enter fullscreen mode Exit fullscreen mode

This helps identify which pages need correction.

How Do I Fix Upside-Down Scanned Pages?

Common scenario for scanned documents:

using IronPdf;
// Install via NuGet: Install-Package IronPdf

public void FixScannedPdf(string inputPath, string outputPath)
{
    var pdf = PdfDocument.FromFile(inputPath);

    // Check each page's rotation and fix if needed
    for (int i = 0; i < pdf.PageCount; i++)
    {
        var current = pdf.GetPageRotation(i);

        // If page is upside down, rotate it back
        if (current == PdfPageRotation.Clockwise180)
        {
            pdf.SetPageRotation(i, PdfPageRotation.None);
        }
    }

    pdf.SaveAs(outputPath);
}
Enter fullscreen mode Exit fullscreen mode

How Do I Create Mixed Orientation Documents?

Some documents need both portrait and landscape pages:

using IronPdf;
// Install via NuGet: Install-Package IronPdf

// Create portrait pages
var portraitRenderer = new ChromePdfRenderer();
portraitRenderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Portrait;

var coverPage = portraitRenderer.RenderHtmlAsPdf("<h1>Annual Report</h1>");
var summaryPage = portraitRenderer.RenderHtmlAsPdf("<h2>Executive Summary</h2><p>...</p>");

// Create landscape pages for charts
var landscapeRenderer = new ChromePdfRenderer();
landscapeRenderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape;

var chartPage = landscapeRenderer.RenderHtmlAsPdf(@"
    <h2>Financial Charts</h2>
    <div style='width:100%;'><!-- Wide chart --></div>
");

// Merge into single document
var combined = PdfDocument.Merge(coverPage, summaryPage, chartPage);
combined.SaveAs("mixed-orientation-report.pdf");
Enter fullscreen mode Exit fullscreen mode

How Do I Convert Portrait to Landscape?

Existing PDFs can be rotated to change effective orientation:

using IronPdf;
// Install via NuGet: Install-Package IronPdf

var pdf = PdfDocument.FromFile("portrait-document.pdf");

// Rotate 90° to view as landscape
pdf.SetAllPageRotations(PdfPageRotation.Clockwise90);

pdf.SaveAs("viewed-as-landscape.pdf");
Enter fullscreen mode Exit fullscreen mode

Note: This rotates the content, not the page dimensions. For true reflow, regenerate from source.

How Do I Set Paper Size with Orientation?

Combine paper size and orientation:

using IronPdf;
// Install via NuGet: Install-Package IronPdf

var renderer = new ChromePdfRenderer();

// A4 Landscape
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape;

// US Letter Portrait
renderer.RenderingOptions.PaperSize = PdfPaperSize.Letter;
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Portrait;

// Custom size (width x height in millimeters)
renderer.RenderingOptions.SetCustomPaperSizeInMillimeters(297, 210); // A4 Landscape
Enter fullscreen mode Exit fullscreen mode

When setting custom sizes, width > height creates landscape.

How Do I Handle URL Rendering with Orientation?

Web pages often need landscape for full-width capture:

using IronPdf;
// Install via NuGet: Install-Package IronPdf

var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape;
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;

// Capture wide dashboard or spreadsheet view
var pdf = renderer.RenderUrlAsPdf("https://example.com/dashboard");
pdf.SaveAs("dashboard-capture.pdf");
Enter fullscreen mode Exit fullscreen mode

How Do I Batch Process Rotation?

Fix orientation across multiple files:

using IronPdf;
// Install via NuGet: Install-Package IronPdf

public void BatchRotate(string inputFolder, string outputFolder,
    PdfPageRotation rotation)
{
    var files = Directory.GetFiles(inputFolder, "*.pdf");

    foreach (var file in files)
    {
        var pdf = PdfDocument.FromFile(file);
        pdf.SetAllPageRotations(rotation);

        var outputPath = Path.Combine(outputFolder, Path.GetFileName(file));
        pdf.SaveAs(outputPath);
        pdf.Dispose();

        Console.WriteLine($"Rotated: {Path.GetFileName(file)}");
    }
}

// Usage
BatchRotate("C:/Scans", "C:/Corrected", PdfPageRotation.Clockwise90);
Enter fullscreen mode Exit fullscreen mode

How Do I Auto-Detect and Fix Orientation?

Check page dimensions to determine orientation:

using IronPdf;
// Install via NuGet: Install-Package IronPdf

public void NormalizeToPotrait(string pdfPath)
{
    var pdf = PdfDocument.FromFile(pdfPath);

    for (int i = 0; i < pdf.PageCount; i++)
    {
        var pageInfo = pdf.GetPageInfo(i);

        // If width > height, page is landscape
        if (pageInfo.Width > pageInfo.Height)
        {
            // Rotate to portrait
            pdf.SetPageRotation(i, PdfPageRotation.Clockwise270);
        }
    }

    pdf.SaveAs(pdfPath.Replace(".pdf", "-portrait.pdf"));
}
Enter fullscreen mode Exit fullscreen mode

How Do I Preserve Orientation During Merge?

Merged PDFs retain each page's original orientation:

using IronPdf;
// Install via NuGet: Install-Package IronPdf

var portrait1 = PdfDocument.FromFile("portrait-page.pdf");
var landscape1 = PdfDocument.FromFile("landscape-chart.pdf");
var portrait2 = PdfDocument.FromFile("portrait-appendix.pdf");

// Each page keeps its orientation
var merged = PdfDocument.Merge(portrait1, landscape1, portrait2);
merged.SaveAs("mixed-document.pdf");
Enter fullscreen mode Exit fullscreen mode

Quick Reference

Task Code
Set portrait RenderingOptions.PaperOrientation = PdfPaperOrientation.Portrait
Set landscape RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape
Rotate all pages pdf.SetAllPageRotations(PdfPageRotation.Clockwise90)
Rotate one page pdf.SetPageRotation(pageIndex, rotation)
Rotate multiple pdf.SetPageRotations(pageIndices, rotation)
Get rotation pdf.GetPageRotation(pageIndex)
Rotation Value Degrees
None
Clockwise90 90°
Clockwise180 180°
Clockwise270 270°

Orientation sets the initial layout. Rotation fixes existing pages. Both are essential for professional PDF workflows.

For more orientation options, see the IronPDF page orientation documentation.


Written by Jacob Mellor, CTO at Iron Software. Jacob created IronPDF and leads a team of 50+ engineers building .NET document processing libraries.

Top comments (0)