Skip to content

Instantly share code, notes, and snippets.

How to Rotate PDF using C#. For more details: https://kb.conholdate.com/total/net/how-to-rotate-pdf-using-csharp/
using Aspose.Pdf;
namespace AsposeProjects
{
class Program
{
static void Main(string[] args)
{
// Initialize license
License lic = new License();
lic.SetLicense("Aspose.Total.lic");
// Load the PDF
Document originalDoc = new Document("input.pdf");
// Parse the pages
foreach (Page pg in originalDoc.Pages)
{
// Change the page orientation
Rectangle r = pg.MediaBox;
double updatedHeight = r.Width;
double updatedWidth = r.Height;
double updatedLLX = r.LLX;
double updatedLLY = r.LLY + (r.Height - updatedHeight);
pg.MediaBox = new Rectangle(updatedLLX, updatedLLY, updatedLLX + updatedWidth, updatedLLY + updatedHeight);
pg.CropBox = new Rectangle(updatedLLX, updatedLLY, updatedLLX + updatedWidth, updatedLLY + updatedHeight);
// Rotate the page contents
pg.Rotate = Rotation.on270;
}
// Save the rotated PDF file
originalDoc.Save("rotated.pdf");
System.Console.WriteLine("Done");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment