We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Support to add rotated text inside PDF using Aspose.PDF for .NET

Can I add rotated text to a pdf file? How can I do this? For instance, rotate the text 90 degrees.

Please refer to Add Logo.

@soconnell

The latest version of Aspose.PDF for .NET enables you to add rotated text inside PDF document during PDF generation scenario. Please check following different ways to achieve it:

Rotate text Using TextFragment + TextBuilder

//open document 
Document pdfDocument = new Document(); 
//get particular page 
Page pdfPage = (Page)pdfDocument.Pages.Add();

//create text fragment
TextFragment textFragment1 = new TextFragment("main text");
textFragment1.Position = new Position(100, 600);

//set text properties
textFragment1.TextState.FontSize = 12;
textFragment1.TextState.Font = FontRepository.FindFont("TimesNewRoman");

//create rotated text fragment
TextFragment textFragment2 = new TextFragment("rotated text");
textFragment2.Position = new Position(200, 600);

//set text properties
textFragment2.TextState.FontSize = 12;
textFragment2.TextState.Font = FontRepository.FindFont("TimesNewRoman");
textFragment2.TextState.Rotation = 45;

//create rotated text fragment
TextFragment textFragment3 = new TextFragment("rotated text");
textFragment3.Position = new Position(300, 600);

//set text properties
textFragment3.TextState.FontSize = 12;
textFragment3.TextState.Font = FontRepository.FindFont("TimesNewRoman");
textFragment3.TextState.Rotation = 90;

// create TextBuilder object
TextBuilder textBuilder = new TextBuilder(pdfPage);
// append the text fragment to the PDF page
textBuilder.AppendText(textFragment1);
textBuilder.AppendText(textFragment2);
textBuilder.AppendText(textFragment3);
//save document
pdfDocument.Save("TextFragmentTests_Rotated1.pdf");

Rotate text using TextParagraph + TextBuilder (rotated fragments)

//open document 
Document pdfDocument = new Document(); 
//get particular page 
Page pdfPage = (Page)pdfDocument.Pages.Add();

TextParagraph paragraph = new TextParagraph();
paragraph.Position = new Position(200, 600);

//create text fragment
TextFragment textFragment1 = new TextFragment("rotated text");

//set text properties
textFragment1.TextState.FontSize = 12;
textFragment1.TextState.Font = FontRepository.FindFont("TimesNewRoman");
//set rotation
textFragment1.TextState.Rotation = 45;

//create text fragment
TextFragment textFragment2 = new TextFragment("main text");

//set text properties
textFragment2.TextState.FontSize = 12;
textFragment2.TextState.Font = FontRepository.FindFont("TimesNewRoman");

//create text fragment
TextFragment textFragment3 = new TextFragment("another rotated text");

//set text properties
textFragment3.TextState.FontSize = 12;
textFragment3.TextState.Font = FontRepository.FindFont("TimesNewRoman");
//set rotation
textFragment3.TextState.Rotation = -45;

// append the text fragments to the paragraph
paragraph.AppendLine(textFragment1);
paragraph.AppendLine(textFragment2);
paragraph.AppendLine(textFragment3);

// create TextBuilder object
TextBuilder textBuilder = new TextBuilder(pdfPage);
// append the text paragraph to the PDF page
textBuilder.AppendParagraph(paragraph);
//save document
pdfDocument.Save("TextFragmentTests_Rotated2.pdf");

Rotate text using TextFragment + Page.Paragraphs

1. Document pdfDocument = new Document(); 
//get particular page 
Page pdfPage = (Page)pdfDocument.Pages.Add();

//create text fragment
TextFragment textFragment1 = new TextFragment("main text");

//set text properties
textFragment1.TextState.FontSize = 12;
textFragment1.TextState.Font = FontRepository.FindFont("TimesNewRoman");

//create text fragment
TextFragment textFragment2 = new TextFragment("rotated text");

//set text properties
textFragment2.TextState.FontSize = 12;
textFragment2.TextState.Font = FontRepository.FindFont("TimesNewRoman");
//set rotation
textFragment2.TextState.Rotation = 315;

//create text fragment
TextFragment textFragment3 = new TextFragment("rotated text");

//set text properties
textFragment3.TextState.FontSize = 12;
textFragment3.TextState.Font = FontRepository.FindFont("TimesNewRoman");
//set rotation
textFragment3.TextState.Rotation = 270;

pdfPage.Paragraphs.Add(textFragment1);
pdfPage.Paragraphs.Add(textFragment2);
pdfPage.Paragraphs.Add(textFragment3);
//save document
pdfDocument.Save("TextFragmentTests_Rotated3.pdf");