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.
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.
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.
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.
|Article ID:||Published Date:||Last Revised Date:||Platform:||Control:|