VintaSoft Imaging .NET SDK 14.0: Documentation for .NET developer
Vintasoft.Imaging.Pdf.Tree Namespace / PdfPageCollection Class / Swap Methods / Swap(PdfPage,PdfPage) Method
Syntax Example Requirements SeeAlso
In This Topic
    Swap(PdfPage,PdfPage) Method (PdfPageCollection)
    In This Topic
    Swaps two pages in the collection.
    Syntax
    'Declaration
    
    Public Overloads Sub Swap( _
    ByVal firstPage
    First page.
    As PdfPage, _
    ByVal secondPage
    Second page.
    As PdfPage _
    )

    Parameters

    firstPage
    First page.
    secondPage
    Second page.
    Example

    Here is an example that shows how to reorder the pages of PDF document:

    
    ''' <summary>
    ''' Swaps the first and the last pages of PDF document.
    ''' </summary>
    ''' <param name="pdfFileName">The filename of PDF document.</param>
    Public Shared Sub SwapPages(pdfFileName As String)
        ' open PDF documnet
        Using document As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFileName)
            ' get the collection of pages of PDF document
            Dim pages As Vintasoft.Imaging.Pdf.Tree.PdfPageCollection = document.Pages
    
            ' get the page count
            Dim pagesCount As Integer = pages.Count
            ' swap the first and the last pages
            pages.Swap(0, pagesCount - 1)
    
            ' save changes to a file
            document.SaveChanges()
        End Using
    End Sub
    
    
    
    /// <summary>
    /// Swaps the first and the last pages of PDF document.
    /// </summary>
    /// <param name="pdfFileName">The filename of PDF document.</param>
    public static void SwapPages(string pdfFileName)
    {
        // open PDF documnet
        using (Vintasoft.Imaging.Pdf.PdfDocument document =
            new Vintasoft.Imaging.Pdf.PdfDocument(pdfFileName))
        {
            // get the collection of pages of PDF document
            Vintasoft.Imaging.Pdf.Tree.PdfPageCollection pages = document.Pages;
    
            // get the page count
            int pagesCount = pages.Count;
            // swap the first and the last pages
            pages.Swap(0, pagesCount - 1);
    
            // save changes to a file
            document.SaveChanges();
        }
    }
    
    

    Requirements

    Target Platforms: .NET9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    See Also