SwapPages Method (GdPicturePDF)
Swaps two pages specified by their page numbers within the currently loaded PDF document, that means the specified pages change their position with one another in the document.
'Declaration
Public Function SwapPages( _
ByVal As Integer, _
ByVal As Integer _
) As GdPictureStatus
Parameters
- Page1
- The page number of the one page you want to swap. It must be a value from 1 to GdPicturePDF.GetPageCount other than Page2 parameter.
- Page2
- The page number of the other page you want to swap. It must be a value from 1 to GdPicturePDF.GetPageCount other than Page1 parameter.
Return Value
A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.
We strongly recommend always checking this status first.
How to swap the first page and the last page in the PDF document.
Dim caption As String = "Example: SwapPage"
Dim gdpicturePDF As New GdPicturePDF()
If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
Dim count As Integer = gdpicturePDF.GetPageCount()
Dim status As GdPictureStatus = gdpicturePDF.GetStat()
If status = GdPictureStatus.OK Then
If count > 1 Then
status = gdpicturePDF.SwapPages(1, count)
If status = GdPictureStatus.OK Then
If gdpicturePDF.SaveToFile("test_SwapPage.pdf") = GdPictureStatus.OK Then
MessageBox.Show("The pages have been swapped successfully and the file has been saved.", caption)
Else
MessageBox.Show("The pages have been swapped successfully, but the file can't be saved.", caption)
End If
Else
MessageBox.Show("The SwapPages() method has failed with the status: " + status.ToString(), caption)
status = GdPictureStatus.OK
End If
Else
MessageBox.Show("The document must contain at least two pages to follow this example.", caption)
End If
End If
If status <> GdPictureStatus.OK Then
MessageBox.Show("The example HAS NOT been followed successfully. The last error status is: " + status.ToString(), caption)
End If
Else
MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: SwapPage";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
{
int count = gdpicturePDF.GetPageCount();
GdPictureStatus status = gdpicturePDF.GetStat();
if (status == GdPictureStatus.OK)
{
if (count > 1)
{
status = gdpicturePDF.SwapPages(1, count);
if (status == GdPictureStatus.OK)
{
if (gdpicturePDF.SaveToFile("test_SwapPage.pdf") == GdPictureStatus.OK)
MessageBox.Show("The pages have been swapped successfully and the file has been saved.", caption);
else
MessageBox.Show("The pages have been swapped successfully, but the file can't be saved.", caption);
}
else
{
MessageBox.Show("The SwapPages() method has failed with the status: " + status.ToString(), caption);
status = GdPictureStatus.OK;
}
}
else
MessageBox.Show("The document must contain at least two pages to follow this example.", caption);
}
if (status != GdPictureStatus.OK)
MessageBox.Show("The example HAS NOT been followed successfully. The last error status is: " + status.ToString(), caption);
}
else
MessageBox.Show("The file can't be loaded.", caption);
gdpicturePDF.Dispose();