Read the complete article on how to rotate text in PDF documents in C#: https://blog.aspose.com/2022/05/13/rotate-text-inside-pdf-documents-in-csharp/
Last active
May 13, 2022 16:05
-
-
Save aspose-com-gists/64858027248d9961768e71e1aa5edcf8 to your computer and use it in GitHub Desktop.
Rotate Text inside PDF Documents in C# .NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize document object | |
Document pdfDocument = new Document(); | |
// Get particular page | |
var pdfPage = 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("Rotation_TextFragment.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize document object | |
Document pdfDocument = new Document(); | |
// Get particular page | |
var pdfPage = 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("Rotation_TextParagraph.pdf"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment