Rotate PDF Text and Pages in .NET
Rotating PDF text or pages refers to changing the orientation of either the entire page or specific text elements within a PDF document. This rotation can be done in degrees (typically 90, 180, or 270 degrees) to reposition content either clockwise or counterclockwise.
Get started with IronPDF
Start using IronPDF in your project today with a free trial.
How to Rotate PDF File in C#
- 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
Rotate PDF Pages
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 is set to the desired degree, the methods would not affect the output file.
:path=/static-assets/pdf/content-code-examples/how-to/rotating-text-set-page-rotation.cs
using 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");
Imports IronPdf
Imports IronPdf.Rendering
Imports System.Linq
' Import PDF
Private pdf As PdfDocument = 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")
Use CSS3 to Rotate Text
After converting HTML to PDF in .NET, there might be a need to programmatically rotate text or entire pages. A frequent requirement is to render vertically aligned text in PDFs using HTML5 and CSS3. Here’s how you can achieve this.
CSS3 allows text rotation to any angle after converting a PDF to HTML using the IronPDF .NET Library you installed earlier. This is achieved using the -webkit-transform: rotate
CSS3 style, which can rotate any HTML element to any angle.
-webkit-transform allows many types of 3D and 3D rotational transforms and effects for HTML elements. A short example of C# HTML to PDF with text rotated 180 degrees is:
:path=/static-assets/pdf/content-code-examples/how-to/rotating-text-css.cs
using 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");
Imports IronPdf
Private renderer = New IronPdf.ChromePdfRenderer()
Private 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")