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(@"
    <meta charset = 'utf-8'>
    -webkit-transform: rotate(-90deg);

<p class='rotated'>Rotated Text</p>

Dim Renderer As var = New IronPdf.HtmlToPdf
Renderer.PrintOptions.InputEncoding = System.Text.Encoding.UTF8
Dim Pdf As var = Renderer.RenderHtmlAsPdf(""& vbLf&"<html>"& vbLf&"<head>"& vbLf&"    <meta charset = 'utf-8'>"& vbLf&"    <style>"& vbLf&"    .rotated{"& vbLf&"    -webkit-transform: rotate(-"& _ 
    "90deg);"& vbLf&"    width:400;"& vbLf&"    height:400;"& vbLf&"    }"& vbLf&"</style>"& vbLf&"</head>"& vbLf&"<body>"& vbLf& vbLf&"<p class='rotated'>Rotated Tex"& _ 
    "t</p>"& vbLf&"</body>"& vbLf&"</html>"& vbLf)
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.