Rotate PDF Page Content

Hello,

I have a PDF where the page has rotated by 270 degrees for printing (so PDFPage.Rotate = 270). I would like to reset that back to 0 but then rotate all the content 270 degrees so that it displays the same without having to deal with non 0-degree based orientations for the annotations on the page.

Thank you for any help you can provide

Hi Dawson,

I’m not exactly sure what you would like to achieve, nevertheless, can you try the following:

using (var document = PdfDocument.Load("input.pdf"))
{
    foreach (var page in document.Pages)
    {
        page.Rotate = 0;

        var elements = page.Content.Elements;
        var contentGroup = elements.Group(elements.First, elements.Last);

        var pageSize = page.Size;
        double scale = pageSize.Width / pageSize.Height;

        var transform = new PdfMatrix(scale, 0, 0, scale, pageSize.Width, 0);
        transform.Rotate(90);

        //var transform = new PdfMatrix(scale, 0, 0, scale, 0, pageSize.Width);
        //transform.Rotate(270);

        contentGroup.Transform = transform;
    }

    document.Save("output.pdf");
}

Here is the screenshot of the “input.pdf” (on the left) and the resulting “output.pdf” (on the right):

I hope this helps.

Regards,
Mario