You can read all details at: Rotate PDF Pages, the Text or Image with C# or VB.NET
Created
January 19, 2021 20:06
-
-
Save aspose-com-gists/e9637e99932cbbf4f82455094769173b to your computer and use it in GitHub Desktop.
Rotate PDF pages, images or text using C# or VB.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
// Load input PDF document | |
Document document = new Document(dataDir + "Rotate.pdf"); | |
// Iterate through each page of PDF | |
foreach(Page page in document.Pages) | |
{ | |
// Rotate the PDF document on desired angle | |
page.Rotate = Rotation.on180; | |
} | |
// Save output rotated PDF file | |
document.Save(dataDir + "Rotated.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
// Open document | |
Document pdfDocument = new Document(dataDir + "Image.pdf"); | |
// Create image stamp | |
ImageStamp imageStamp = new ImageStamp(dataDir + "Image.jpg"); | |
imageStamp.XIndent = 100; | |
imageStamp.YIndent = 100; | |
imageStamp.Height = 300; | |
imageStamp.Width = 300; | |
imageStamp.Rotate = Rotation.on90; | |
imageStamp.Opacity = 0.5; | |
// Add stamp to particular page | |
pdfDocument.Pages[1].AddStamp(imageStamp); | |
dataDir = dataDir + "RotatedImage.pdf"; | |
// Save output document | |
pdfDocument.Save(dataDir); |
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
// Load input PDF document | |
Document document = new Document(dataDir + "Rotate.pdf"); | |
// Specify the page numbers you want to apply rotation on | |
int[] pages = { 1, 3, 7 }; | |
// Iterate through particular pages | |
foreach (Page page in document.Pages) | |
{ | |
foreach (int match in pages) | |
{ | |
if (page.Number == match) | |
{ | |
// Rotate the page | |
page.Rotate = Rotation.on90; | |
} | |
} | |
} | |
// Save rotated PDF document | |
document.Save(dataDir + "Rotated.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 | |
Document pdfDocument = new Document(); | |
// Get particular page | |
Page pdfPage = pdfDocument.Pages.Add(); | |
// Create text fragment | |
TextFragment tf = new TextFragment("Rotated text"); | |
// Add text at specific loaction on the page | |
tf.Position = (new Position(200, 600)); | |
// Set text properties | |
tf.TextState.FontSize = 12; | |
tf.TextState.Font = FontRepository.FindFont("TimesNewRoman"); | |
tf.TextState.BackgroundColor = Aspose.Pdf.Color.LightGray; | |
tf.TextState.ForegroundColor = Aspose.Pdf.Color.Red; | |
tf.TextState.Rotation = 45; | |
tf.TextState.Underline = true; | |
// Create TextBuilder object | |
TextBuilder textBuilder = new TextBuilder(pdfPage); | |
// Append the text fragment to the PDF page | |
textBuilder.AppendText(tf); | |
// Save document | |
pdfDocument.Save(dataDir + "Text_Rotated.pdf"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment