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:
First things first:
<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>
If you need to rotate pages that are displayed upside down or with incorrect orientation, you can do this in the PDF Viewer:
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.
To remove pages in a PDF document, follow these steps:
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.
To rearrange the pages in a PDF document, follow these steps:
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.
You can download the samples from the following GitHub repositories:
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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!
[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