Rotate PDF Text and Pages in C# with IronPDF
IronPDF enables C# developers to rotate PDF pages and text programmatically using simple methods like SetPageRotation() for complete pages or CSS3 transforms for specific text elements, supporting rotations of 90, 180, or 270 degrees clockwise.
Rotating PDF text or pages changes the orientation of either entire pages or specific text elements within a PDF document. This rotation occurs in degrees (typically 90, 180, or 270) to reposition content clockwise or counterclockwise. This capability is essential for correcting scanned documents, creating landscape reports, or adjusting content presentation for specific viewing requirements.
Quickstart: Rotate PDF Pages in .NET with IronPDF
Easily rotate PDF pages in your .NET applications using IronPDF. With just a few lines of code, you can adjust the orientation of your PDF content to any desired angle. This quickstart guide shows you how to rotate the first page of a PDF document by 90 degrees and save the changes effortlessly. Perfect for developers looking to enhance document presentation with minimal effort.
Get started making PDFs with NuGet now:
Install IronPDF with NuGet Package Manager
Copy and run this code snippet.
IronPdf.PdfDocument.FromFile("input.pdf") .SetAllPageRotations(IronPdf.PdfPageRotation.Clockwise90) .SaveAs("rotated.pdf");Deploy to test on your live environment
Minimal Workflow (5 steps)
- Download IronPDF C# PDF Library to rotate PDF
- Use the provided methods to set page rotation
- Rotate PDF Pages Programmatically
- Use CSS3 to Rotate PDF Text
- View your PDF Document
How Do I Rotate PDF Pages Programmatically?
Which Methods Should I Use for Different Rotation Scenarios?
Use the SetPageRotation, SetPageRotations, and SetAllPageRotations methods to set rotation for a single page, multiple pages, and all pages, respectively. These methods completely overwrite the current page rotation with the specified degree, measured clockwise. If the original page rotation already matches the desired degree, the methods won't affect the output file.
The IronPDF library provides comprehensive page orientation and rotation capabilities that integrate seamlessly with existing PDF workflows. Whether you're working with newly created PDFs or existing documents, these rotation methods offer precise control over page orientation without affecting the actual content structure.
What Rotation Angles Are Supported?
IronPDF supports four standard rotation angles: 0° (no rotation), 90°, 180°, and 270° clockwise. These angles cover all common rotation requirements for PDF documents. The rotation is applied at the page level, meaning the entire page content, including text, images, and graphics, rotates as a single unit. This approach maintains the spatial relationships between elements on the page.
:path=/static-assets/pdf/content-code-examples/how-to/rotating-text-set-page-rotation.csusing IronPdf;
using IronPdf.Rendering;
using System.Linq;
// Import PDF
PdfDocument pdf = PdfDocument.FromFile("multi-page.pdf");
// Set rotation for a single page
pdf.SetPageRotation(0, PdfPageRotation.Clockwise90);
// Set rotation for multiple pages
pdf.SetPageRotations(Enumerable.Range(1,3), PdfPageRotation.Clockwise270);
// Set rotation for the entire document
pdf.SetAllPageRotations(PdfPageRotation.Clockwise180);
pdf.SaveAs("rotated.pdf");When working with page rotations, it's important to understand how they interact with other PDF features. For example, if you're also using custom paper sizes, the rotation will be applied after the page size is set. This means a portrait page rotated 90 degrees will effectively become landscape oriented.
How Can I Use CSS3 to Rotate Text in PDFs?
Why Use CSS3 Transform Instead of Page Rotation?
After converting HTML to PDF in .NET, you might need to programmatically rotate text or entire pages. A frequent requirement is rendering vertically aligned text in PDFs using HTML5 and CSS3. CSS3 transforms offer more granular control compared to page-level rotation, allowing you to rotate individual text elements or sections while keeping the rest of the page in its original orientation.
This approach is particularly useful when creating documents with mixed orientations, such as reports with vertical labels on charts or tables with rotated headers. The HTML to PDF conversion process in IronPDF fully supports CSS3 transforms, ensuring your styled content appears exactly as intended in the final PDF.
What CSS Properties Control Text Rotation?
CSS3 allows text rotation to any angle after converting HTML to PDF using the IronPDF .NET Library you installed earlier. This is achieved using the transform: rotate(...) CSS3 style, which can rotate any HTML element to any angle. The rotation origin can be customized using the transform-origin property, giving you complete control over the rotation pivot point.
:path=/static-assets/pdf/content-code-examples/how-to/rotating-text-css.csusing IronPdf;
var renderer = new IronPdf.ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(@"
<html>
<head>
<style>
.rotated{
-webkit-transform: rotate(-180deg);
width:400;
height:400;
}
</style>
</head>
<body>
<p class='rotated'>Rotated Text</p>
</body>
</html>
");
pdf.SaveAs("rotated.pdf");The CSS3 transform property supports various rotation units including degrees (deg), radians (rad), gradians (grad), and turns. For PDF generation, degrees are most commonly used. You can also combine rotation with other transforms like scale and translate to achieve complex positioning effects. When using responsive CSS with IronPDF, these transforms adapt seamlessly to different page sizes and orientations.
For more advanced scenarios, you might want to explore transforming PDF pages programmatically after the initial render. This allows you to apply additional transformations to existing PDFs or combine CSS-based rotations with page-level transformations for complex document layouts.
Ready to see what else you can do? Check out our tutorial page here: Edit PDFs or explore how to create new PDFs from scratch with custom orientations. For managing different page orientations within the same document, see our guide on portrait and landscape orientation.
Frequently Asked Questions
How do I rotate specific pages in a PDF document using C#?
IronPDF provides three methods for rotating PDF pages: SetPageRotation() for a single page, SetPageRotations() for multiple pages, and SetAllPageRotations() for all pages. These methods support rotation angles of 90°, 180°, and 270° clockwise, completely overwriting the current page rotation.
What rotation angles are supported for PDF pages?
IronPDF supports four standard rotation angles: 0° (no rotation), 90°, 180°, and 270° clockwise. The rotation is applied at the page level, meaning all content including text, images, and graphics rotates as a single unit while maintaining spatial relationships between elements.
Can I rotate just text elements without rotating the entire PDF page?
Yes, IronPDF allows you to rotate specific text elements using CSS3 transforms. This enables you to rotate individual text components within a page without affecting the overall page orientation, giving you precise control over text presentation.
What's the simplest way to rotate all pages in a PDF by 90 degrees?
The quickest method is using IronPDF's one-line solution: IronPdf.PdfDocument.FromFile("input.pdf").SetAllPageRotations(IronPdf.PdfPageRotation.Clockwise90).SaveAs("rotated.pdf"). This loads your PDF, rotates all pages 90 degrees clockwise, and saves the result.
Will rotating a PDF page affect the content structure?
No, IronPDF's rotation methods maintain the content structure intact. The rotation occurs at the page level without affecting the actual content relationships. Text remains selectable, links stay functional, and the document's internal structure is preserved.
How can I correct the orientation of scanned documents programmatically?
IronPDF is ideal for correcting scanned document orientations. Use the SetPageRotation() method to rotate individual pages or SetAllPageRotations() to fix the entire document. This is particularly useful for batch processing scanned PDFs that may have inconsistent orientations.






