Rotate, Remove, and Rearrange PDF Pages Easily with WPF PDF Viewer | Syncfusion Blogs
Detailed Blog page Skeleton loader
Rotate, Remove, and Rearrange PDF Pages Easily with WPF PDF Viewer

Usually, PDF files created from scanning physical papers will require rotating, rearranging, and the removal of redundant pages. The Syncfusion WPF PDF Viewer is a single-stop shop for performing these operations in a PDF document quickly and easily.

The support for multiple-page selection and miniature previews (thumbnails) in the PDF Viewer will help you review, select, and organize the pages in large PDF files in a matter of seconds. In this blog, we will explore how to perform the following operations interactively and with code examples:

Getting started

First things first:

  1. Create a new WPF project and install the PDF Viewer NuGet package.
  2. Include the following code in your XAML page to add the PDF Viewer as a child to window.
    <Window x:Class="PdfViewer.MainWindow" 
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:pdfviewer="clr-namespace:Syncfusion.Windows.PdfViewer;assembly=Syncfusion.PdfViewer.WPF"
            Title="PDF Viewer">
        <pdfviewer:PdfViewerControl x:Name="pdfViewer"/>
    </Window>

How to rotate pages in a PDF

If you need to rotate pages that are displayed upside down or with incorrect orientation, you can do this in the PDF Viewer:

  1. Open the PDF file in PDF Viewer using the open button.
  2. Click the organize pages icon  organize pages icon in the left toolbar to display the thumbnails of PDF pages.
  3. Select the page you want to rotate. To select multiple pages, hold down the Ctrl key and click them all.
  4. Click the counterclockwise icon  counterclockwise icon or clockwise icon clockwise icon  in the toolbar to rotate the selected pages 90 degrees with respect to the current page position.
  5. After performing the operation, close the organizing pages view.
Rotating pages of a PDF
Rotating pages of a PDF

You can also rotate the pages from the application level using the built-in APIs. The following code example elaborates on how to rotate specific PDF pages to a specific angle and direction.

To rotate the pages to a specific angle

private void RotatePages()
{
   int[] pageIndexes = new int[] { 0, 2, 6 };
   // Rotates the PDF pages 90 degrees regardless of its current rotation angle. 
   pdfViewer.PageOrganizer.Rotate(pageIndexes, PdfPageRotateAngle.RotateAngle90);
}

To rotate specific pages clockwise

private void RotatePagesClockwise()
{
    int[] pageIndexes = new int[] { 0, 2, 6 };
    // Rotates the PDF pages 90 degrees clockwise with respect to the current rotation angle.
    pdfViewer.PageOrganizer.RotateClockwise(pageIndexes);
}

To rotate specific pages counterclockwise

private void RotatePagesCounterclockwise()
{
    int[] pageIndexes = new int[] { 0, 2, 6 };
    // Rotates the PDF pages to 90 degrees in counterclockwise direction with respect to the current rotation angle.
    pdfViewer.PageOrganizer.RotateCounterclockwise(pageIndexes);
}

Note: You can rotate PDF pages 90, 180, 270, and 360 degrees only.

How to remove pages in a PDF

To remove pages in a PDF document, follow these steps:

  1. Open the input PDF file in PDF Viewer.
  2. Click the organize pages icon organize pages icon in the left toolbar to display the thumbnails of the PDF pages.
  3. Select the page you want to remove. To select multiple pages, hold down the Ctrl key and select them all.
  4. Click the delete icon Delete icon  in the toolbar to remove the selected pages.
  5. Once the operation is performed, close the organizing pages view.
Remove pages in a PDF
Remove pages in a PDF

You can also remove pages at the application level using the built-in APIs. The following code example elaborates on how to remove specific pages in a PDF file.

To remove a page at a specific index

private void RemovePage()
{
   // Removes a page at a specific index.
   pdfViewer.PageOrganizer.RemoveAt(2);
}

To remove specific pages

private void RemovePages()
{
   int[] pageIndexes = new int[] { 0, 2, 6 };
   // Removes specific pages in a PDF file.
   pdfViewer.PageOrganizer.RemovePages(pageIndexes);
}

Note: You cannot remove all the pages in a PDF file. You need to retain at least one page.

How to rearrange pages in a PDF

To rearrange the pages in a PDF document, follow these steps:

  1. Open the PDF file in PDF Viewer.
  2. Click the organize pages icon organize pages icon in the left toolbar to display the thumbnails of the PDF pages.
  3. Select the page you want to reorder. To select multiple pages, hold down the Ctrl key and select them all.
  4. Drag the selected pages to the location to which you need to move them. This will rearrange the pages automatically.
  5. Once you’ve performed the operation, close the organizing pages view for further processing.
Rearrange pages in a PDF
Rearrange pages in a PDF

You can also rearrange the pages at the application level using the built-in APIs. The following code example elaborates on how to rearrange the pages in a PDF file with the expected page order.

private void RearrangePages()
{
    int[] expectedOrder = new int[] { 1, 0, 2 };
    // Rearranges the pages in a PDF file with 3 pages in the expected order.
    pdfViewer.PageOrganizer.ReArrange(expectedOrder);
}

Note: The length of the expected order should be equal to the original page count.

Resources

You can download the samples from the following GitHub repositories:

Conclusion

Thank you for reading this blog. I hope that this information helps you organize your PDF file into a professional-looking document. You can find demos of other PDF Viewer features in this GitHub repository.

Feel free to share your feedback or questions in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

See also

[Blog] Top 10 Features of Syncfusion WPF PDF Viewer

[Blog] Problems Applying Right-to-Left Rendering in WPF PDF Viewer?

[Blog] PDF to Image Conversion is Made Easy with WPF PDF Viewer

[Blog] Inking PDF Documents with Essential PDF Viewer

Be the first to get updates

Deepak G

Meet the Author

Deepak G

Deepak is a Product Manager at Syncfusion with specialized skills in XAML, MVVM, and Windows platform-based controls. In 2014, he started his career as a Software Developer and has become a technophile.