I’ve used this C# code and it works very well.
https://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Page-Setting/How-to-rotate-the-PDF-file-in-C.html
Here’s a thread with all the doubts cleared for this part