C#/VB.NET: Rearrange Pages in PDF

2022-04-27 07:29:00 Written by  support iceblue
Rate this item
(0 votes)

For PDF documents with pages out of order, rearranging the pages can avoid confusing the reader and also make the document more organized. This article will demonstrate how to programmatically rearrange the pages in an existing PDF document using Spire.PDF for .NET.

Install Spire.PDF for .NET

To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.PDF

Rearrange Pages in an Existing PDF Document

  • Create a PdfDocument object.
  • Load a sample PDF document using PdfDocument.LoadFromFile() method.
  • Get the pages in the PDF document using PdfDocument.Pages property.
  • Rearrange PDF pages using PdfPageCollection.ReArrange(int[] orderArray) method.
  • Save the document to another file using PdfDocument.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Pdf;

namespace RearrangePDF
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a PdfDocument object
            PdfDocument pdf = new PdfDocument();

            //Load a sample PDF document
            pdf.LoadFromFile("input.pdf");

            //Rearrange pages by page index
            pdf.Pages.ReArrange(new int[] { 1, 0, 2, 3 });

            //Save the document
            pdf.SaveToFile("ChangeOrder.pdf");
            pdf.Close();
        }
    }
}

C#/VB.NET: Rearrange Pages in PDF

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Additional Info

  • tutorial_title:
Last modified on Tuesday, 20 June 2023 01:56