We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to reorder PDF pages using ListView?

You can rearrange the PDF pages by extracting the pages as images using PDF viewer, loading them into a ListView, and dragging to the position you need. The rearranged PDF can be saved using the PdfLoadedDocument.

 

Include a ListView to load the pages and a button to save the PDF. The CanReorderItems, CanDragItems, and AllowDrop properties of the ListView must be set to “True”. Add a Grid that contains an Image control to the ListView’s ItemTemplate. The pages are rendered on these Image controls.

 

XAML

 

Add a new class named CustomImage to the project. It must have two properties of type ImageSource and int with the names PageImageSource and PageNumber respectively. The Source property of the Image control in the ListView’s ItemTemplate can bound to the PageImageSource property. The other integer property helps to identify the original page number associated with the image.

 

 

C#

 

Add a ViewModel class to the project with the name “RearrangePagesViewModel”. Define a property of type ObservableCollection<CustomImage> in this class. The ItemsSource property of the ListView must bound to this property as shown in the previous XAML code. 

Implement the logic of exporting the PDF pages as images using PDF viewer and adding them to the PageList in the constructor of the RearrangePagesViewModel class. Define an asynchronous method that implements this logic and call the method from the constructor, as the keyword async cannot be used with the constructor.

 

C#

 

In the main page of the project, get the stream of the PDF to be loaded and create a PdfLoadedDocument instance and in the constructor, initialize the RearrangePagesViewModel class. Define and wire a handler method for the Click event  of the save button as shown in the XAML code. In this method, implement the logic to save the PDF with the current page order as displayed in the ListView. The file is saved to the LocalFolder of the application.

 

C#

 

Sample link:

http://www.syncfusion.com/downloads/support/directtrac/general/ze/RearrangePagesDemo-966812100

Article ID: Published Date: Last Revised Date: Platform: Control:
8813 05/31/2018 07/05/2018 UWP SfPdfViewer
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.