Rotating PDF Text to any Angle

Rotating Text to any Angle in a .NET HTML to PDF conversion may be achieved using CSS3. A common request is to render vertically aligned text to a PDF using HTML5.

The magic is knowing of the “-webkit-transform: rotate” CSS style, which may be used to rotate any HTML element though any angle. -webkit-transform allows many types of 3d and 3d rotational transforms and effects for HTML elements.

An example of C# HTML to PDF with text rotated though 270 degrees is:

var Renderer = new IronPdf.HtmlToPdf();
Renderer.PrintOptions.InputEncoding = System.Text.Encoding.UTF8;

var Pdf = Renderer.RenderHtmlAsPdf(@"
<html>
<head>
    <meta charset = 'utf-8'>
    <style>
    .rotated{
    -webkit-transform: rotate(-90deg);
    width:400;
    height:400;
    }
</style>
</head>
<body>

<p class='rotated'>Rotated Text</p>
</body>
</html>
");

Pdf.SaveAs("rotated.pdf");
Dim Renderer = New IronPdf.HtmlToPdf()
Renderer.PrintOptions.InputEncoding = System.Text.Encoding.UTF8

Dim Pdf = Renderer.RenderHtmlAsPdf("
<html>
<head>
    <meta charset = 'utf-8'>
    <style>
    .rotated{
    -webkit-transform: rotate(-90deg);
    width:400;
    height:400;
    }
</style>
</head>
<body>

<p class='rotated'>Rotated Text</p>
</body>
</html>
")

Pdf.SaveAs("rotated.pdf")
VB   C#

Rotating Entire PDF Pages programmatically

A PDF page may be rotated programmatically in .Net using the IronPdf.PdfDocument.RotatePage Method.

Alternatively, the IronPdf.PdfDocument.RotateAllPages method can be used to rotate an entire PDF in a single line of C#, F# or Visual Basic.