C#: Online Guide
How To: Word SDK
Page: Move Word Page Position
Page: Move Word Page Position
  |  
Home ›› XDoc.Word ›› C# Word: Move Word Page Position

C# Word - Sort Word Pages Order in C#.NET


Support Customizing Page Order of Word Document in C# Project




Overview



RasterEdge C#.NET Word document page reordering control SDK (XDoc.Word) is a thread-safe .NET library that can be used to adjust the Word document pages order. This Word document page reorganizing control condenses quick Word page sorting functions into a compact library, which is compatible with .NET-compliant programming language C#.


Related .net document control helps:
asp.net edit pdf text using c#: ASP.NET PDF Text Edit Control: online edit PDF text content using C# ASP.NET
asp.net document viewer open source: EdgeDoc:ASP.NET Document Viewer C# Control: Open, view, annotate, redact, convert documents online in C#, VB.NET, AS...
asp.net mvc pdf editor using c#: ASP.NET MVC PDF Viewer & Editor: view, annotate, redact, edit PDF document in C# ASP.NET MVC
c# asp.net word document viewer: ASP.NET Office Word Document Viewer: view Word doc files online using C# in ASP.NET MVC web applications
c# asp.net mvc document viewer: ASP.NET MVC Document Viewer: view, annotate, redact files on ASP.NET MVC web projects
asp.net sharepoint document viewer open source: ASP.NET SharePoint Document Viewer: view, annotate, redact documents in SharePoint
c# asp.net tiff viewer: ASP.NET Tiff Viewer: view, annotate multipage Tiff images in ASP.NET MVC, WebForms using C# Control


Using this C#.NET Word document page reorganizing library control, developers can swap or adjust the order of all or several Word document pages, or just change the position of certain one Word page in an extremely easy and quick way using C# code.


Besides C#.NET Word document page sorting function, RasterEdge has also offered other .NET Word page processing functions, like Word documents merging, Word page rotating, Word image extracting, Word page inserting, Word page deleting and Word document splitting.




C# DLLs: Move Word Page Position



Add references:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.XDoc.Office.Inner.Common.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XDoc.Office.Inner.Office03.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.XDoc.Word.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XImage.Raster.dll


Use corresponding namespaces;


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.Word;




Swap Two Word Pages Position Using C#



You may choose two pages of Word file and exchange their position.




String filepath = @"";
String outPutFilePath = @"";
DOCXDocument doc = new DOCXDocument(filepath);

// Swap page 0 and page 1.
doc.SwapTwoPages(0, 1);

// Save Word document.
doc.Save(outPutFilePath);





Sort Multiple Word Pages with a Certain Order in C#.NET



Use C# sample code below to sort several pages of Word file to your desired order.




//  get WordDocument object from a source file
String inputFilePath = Program.RootPath + "\\" + "1.docx";
DOCXDocument doc = new DOCXDocument(inputFilePath);

//  show page count of the document
int pageCount = doc.GetPageCount();
Console.WriteLine("Page Count: " + pageCount);

//  define the new order for all pages
//  1. the length of the array MUST BE equal to pageCount
//  2. each page index SHOULD be in the array and only once
//  otherwise, the method would throw exception
int[] pageOrders = new int[] { 1, 3, 0, 5, 4, 6, 2 };
doc.SortPage(pageOrders);

//  save the WordDocument
String outputFilePath = Program.RootPath + "\\" + "Output.docx";
doc.Save(outputFilePath);