Cómo configurar la orientación y rotación de página en .NET C# | IronPDF

How to Set Page Orientation and Rotation

This article was translated from English: Does it need improvement?
Translated
View the article in English

Page Orientation refers to how a page is laid out, either vertically (portrait) or horizontally (landscape).

Page Rotation is the adjustment of a page's angle, allowing you to change its orientation, which can be useful for correcting alignment or meeting specific viewing preferences. Page angles can be set at 90, 180, and 270 degrees.

IronPDF allows you to specify the orientation as either portrait or landscape during the rendering process. Additionally, you can individually rotate newly rendered or existing PDF pages to angles of 0, 90, 180, or 270 degrees as needed.

Quickstart: Set PDF Page Orientation and Rotation in C#

Effortlessly set page orientation and rotation in your PDF files using IronPDF in .NET C#. Begin by loading your PDF, then apply desired rotations or orientations with simple method calls. Save your updated document swiftly, ensuring your layout meets any specific requirements. This quick guide helps you get started without hassle.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. Copy and run this code snippet.

    IronPdf.PdfDocument.FromFile("file.pdf")
        .SetAllPageRotations(IronPdf.PdfDocument.PageRotation.Rotate90)
        .SaveAs("rotated.pdf");
  3. Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer


Page Orientation Example

Setting the orientation is only possible when generating a PDF document from other formats. You can access the PaperOrientation property from the RenderingOptions class. This property can be set to either portrait or landscape. Portrait is the default page orientation setting.

Code

:path=/static-assets/pdf/content-code-examples/how-to/page-orientation-rotation-orientation.cs
using IronPdf;
using IronPdf.Rendering;

ChromePdfRenderer renderer = new ChromePdfRenderer();

// Change paper orientation
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape;

PdfDocument pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");

pdf.SaveAs("landscape.pdf");
Imports IronPdf
Imports IronPdf.Rendering

Private renderer As New ChromePdfRenderer()

' Change paper orientation
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape

Dim pdf As PdfDocument = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page")

pdf.SaveAs("landscape.pdf")
$vbLabelText   $csharpLabel

Output PDF


Page Rotation Example

There are four possible rotation degrees offered by IronPDF:

  • None: 0 degrees or non-rotated document.
  • Clockwise90: 90 degrees rotated clockwise.
  • Clockwise180: 180 degrees rotated clockwise.
  • Clockwise270: 270 degrees rotated clockwise.

Por favor notaAll page index positions mentioned below follow zero-based indexing.

Set Page Rotation

Use methods below to set the rotation for a single page, multiple pages, or all pages.

  • SetAllPageRotations: Sets the rotation degree for all pages.
  • SetPageRotation: Sets the rotation degree for a single page.
  • SetPageRotations: Sets the rotation degree for a selected list of pages.
:path=/static-assets/pdf/content-code-examples/how-to/page-orientation-rotation-set-rotation.cs
using IronPdf;
using IronPdf.Rendering;
using System.Collections.Generic;

PdfDocument pdf = PdfDocument.FromFile("landscape.pdf");

// Set all pages
pdf.SetAllPageRotations(PdfPageRotation.Clockwise90);

// Set a single page
pdf.SetPageRotation(1, PdfPageRotation.Clockwise180);

// Set multiple pages
List<int> selectedPages = new List<int>() { 0, 3 };
pdf.SetPageRotations(selectedPages, PdfPageRotation.Clockwise270);

pdf.SaveAs("rotatedLandscape.pdf");
Imports IronPdf
Imports IronPdf.Rendering
Imports System.Collections.Generic

Private pdf As PdfDocument = PdfDocument.FromFile("landscape.pdf")

' Set all pages
pdf.SetAllPageRotations(PdfPageRotation.Clockwise90)

' Set a single page
pdf.SetPageRotation(1, PdfPageRotation.Clockwise180)

' Set multiple pages
Dim selectedPages As New List(Of Integer)() From {0, 3}
pdf.SetPageRotations(selectedPages, PdfPageRotation.Clockwise270)

pdf.SaveAs("rotatedLandscape.pdf")
$vbLabelText   $csharpLabel

Output PDF

Get Page Rotation

Use the GetPageRotation method to retrieve the rotation of any particular page in the PDF document. Simply supply the page index to the method.

:path=/static-assets/pdf/content-code-examples/how-to/page-orientation-rotation-get-rotation.cs
using IronPdf;
using IronPdf.Rendering;

PdfDocument pdf = PdfDocument.FromFile("rotatedLandscape.pdf");

PdfPageRotation rotation = pdf.GetPageRotation(1);
Imports IronPdf
Imports IronPdf.Rendering

Private pdf As PdfDocument = PdfDocument.FromFile("rotatedLandscape.pdf")

Private rotation As PdfPageRotation = pdf.GetPageRotation(1)
$vbLabelText   $csharpLabel

Preguntas Frecuentes

¿Cómo puedo establecer la orientación de la página en un PDF usando C#?

Puede establecer la orientación de la página usando la propiedad PaperOrientation de la clase RenderingOptions en IronPDF. Esta propiedad puede configurarse en vertical u horizontal antes de renderizar el PDF.

¿Cuáles son los ángulos de rotación posibles para las páginas PDF?

IronPDF le permite rotar páginas PDF a cuatro ángulos posibles: 0 grados (Ninguno), 90 grados (90 grados a la derecha), 180 grados (180 grados a la derecha) y 270 grados (270 grados a la derecha).

¿Cómo se rotan todas las páginas en un documento PDF usando C#?

Puede rotar todas las páginas en un documento PDF usando el método SetAllPageRotations de IronPDF, especificando el ángulo de rotación deseado (por ejemplo, PdfPageRotation.Clockwise90).

¿Es posible rotar páginas específicas dentro de un PDF usando C#?

Sí, puede rotar páginas específicas usando el método SetPageRotation de IronPDF para una sola página o SetPageRotations para múltiples páginas proporcionando sus índices.

¿Cómo puedo determinar la rotación actual de una página PDF?

Puede usar el método GetPageRotation en IronPDF para obtener el ángulo de rotación de una página específica proporcionando el índice de la página.

¿Cuál es la orientación de página predeterminada al crear un nuevo PDF?

La orientación de página predeterminada al crear un nuevo PDF con IronPDF es vertical.

¿Necesito alguna biblioteca adicional para manipular la orientación y rotación de páginas en PDFs?

Sí, necesitará descargar la biblioteca IronPDF C# para manipular la orientación y rotación de páginas en PDFs.

¿Cuál es el beneficio de usar IronPDF para la manipulación de PDF en C#?

IronPDF proporciona un conjunto completo de herramientas para crear, editar y manipular documentos PDF en C#, incluyendo la configuración de orientación y rotación de página, lo que mejora la presentación del documento y se alinea con preferencias específicas de visualización.

¿IronPDF es totalmente compatible con .NET 10, incluidas las funciones de orientación y rotación?

Sí: IronPDF es compatible con .NET 10 junto con versiones anteriores (.NET 9, 8, etc.) y funciona perfectamente con todas las funciones de orientación y rotación de página (como RenderingOptions.PaperOrientation , SetPageRotation , SetAllPageRotations y GetPageRotation ).

Chaknith Bin
Ingeniero de Software
Chaknith trabaja en IronXL e IronBarcode. Tiene un profundo conocimiento en C# y .NET, ayudando a mejorar el software y apoyar a los clientes. Sus conocimientos derivados de las interacciones con los usuarios contribuyen a mejores productos, documentación y experiencia en general.
¿Listo para empezar?
Nuget Descargas 16,154,058 | Versión: 2025.11 recién lanzado