PDFRasterizer.NET 4.0 is now available. Supports .NET Core. Renders pixel-perfectly.

How to mirror PDF pages and other shapes

In this code sample we will mirror the pages in an existing PDF document

In short, this is done by getting the PageShape from each page, and applying a mirror transformation to it and finally add it to a new document. Note that widgets and annotations cannot be flipped; however it is possible to move and rotate them. Although we only look at PageShapes in this sample, mirroring other Shapes is done in the same way.

Mirrored Page 1

using (FileStream fs = new FileStream(@"..\..\../inputdocuments/packinglightbrochure.pdf",FileMode.Open,FileAccess.Read))
{
    //open pdf source
    Document document = new Document(fs);
    //create the new document to add the mirrored pages
    Document mirrored = new Document();

    foreach(Page page in document.Pages)
    {
        //create a pageshape to apply the transformations to
        PageShape pageShape = new PageShape(page);

        MatrixTransform transform = new MatrixTransform();
        //mirror horizontally
        transform.Scale(-1, 1);
        //because the page is out of view after horizontal mirroring, we need to shift it into view again
        transform.Translate(page.Width, 0);

        pageShape.Transform = transform;

        //create a new page from the transformed pageshape and add it to new document
        Page mirroredPage = new Page(page.Width, page.Height);
        mirroredPage.VisualOverlay.Add(pageShape);
        mirrored.Pages.Add(mirroredPage);
    }

    //write the mirrored document to disk
    using (FileStream output = new FileStream(@"..\../out.pdf",FileMode.Create,FileAccess.Write))
    {
        mirrored.Write(output);
    }
}
Download PDFKit.NET 5.0
We will send you a download link

  • This field is for validation purposes and should be left unchanged.
Why do we ask your email address?
We send tips that speed up your evaluation
We let you know about bug fixes
You can always unsubscribe with one click
We never share your address with a 3rd party
Thank you for your download

We have sent an email with a download link.