Rotate, Remove, and Rearrange PDF Pages Easily with WPF PDF Viewer | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (173).NET Core  (29).NET MAUI  (199)Angular  (107)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (40)Black Friday Deal  (1)Blazor  (211)BoldSign  (13)DocIO  (24)Essential JS 2  (106)Essential Studio  (200)File Formats  (63)Flutter  (132)JavaScript  (219)Microsoft  (118)PDF  (80)Python  (1)React  (98)Streamlit  (1)Succinctly series  (131)Syncfusion  (892)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (50)Windows Forms  (61)WinUI  (68)WPF  (157)Xamarin  (161)XlsIO  (35)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (146)Chart  (127)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (62)Development  (618)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (37)Extensions  (22)File Manager  (6)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (497)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (42)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (379)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (17)Web  (582)What's new  (319)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Rotate, Remove, and Rearrange PDF Pages Easily with WPF PDF Viewer

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

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed