GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / InsertPage Method / InsertPage(Single,Single,Int32) Method
The page width expressed in the current units specified by the SetMeasurementUnit method.

You can simply use the GetMeasurementUnit method to determine the currently defined units and you can easily use the SetMeasurementUnit method to reset the units according to your preference.

The page height expressed in the current units specified by the SetMeasurementUnit method.

You can simply use the GetMeasurementUnit method to determine the currently defined units and you can easily use the SetMeasurementUnit method to reset the units according to your preference.

The required position of the page to insert, that means the page number for the newly inserted page. It must be a value greater than 0.

If the specified value is greater than the number of all pages in the loaded document, the new page is automatically inserted as the last page, as it is shown in the example below.

Example





In This Topic
InsertPage(Single,Single,Int32) Method
In This Topic
Inserts a new blank page according to the specified page size, expressed in the current units, and the page position into the currently loaded PDF document. The newly inserted page is automatically selected as the current page.
Syntax
'Declaration
 
Public Overloads Function InsertPage( _
   ByVal PageWidth As Single, _
   ByVal PageHeight As Single, _
   ByVal PageNo As Integer _
) As GdPictureStatus
public GdPictureStatus InsertPage( 
   float PageWidth,
   float PageHeight,
   int PageNo
)
public function InsertPage( 
    PageWidth: Single;
    PageHeight: Single;
    PageNo: Integer
): GdPictureStatus; 
public function InsertPage( 
   PageWidth : float,
   PageHeight : float,
   PageNo : int
) : GdPictureStatus;
public: GdPictureStatus InsertPage( 
   float PageWidth,
   float PageHeight,
   int PageNo
) 
public:
GdPictureStatus InsertPage( 
   float PageWidth,
   float PageHeight,
   int PageNo
) 

Parameters

PageWidth
The page width expressed in the current units specified by the SetMeasurementUnit method.

You can simply use the GetMeasurementUnit method to determine the currently defined units and you can easily use the SetMeasurementUnit method to reset the units according to your preference.

PageHeight
The page height expressed in the current units specified by the SetMeasurementUnit method.

You can simply use the GetMeasurementUnit method to determine the currently defined units and you can easily use the SetMeasurementUnit method to reset the units according to your preference.

PageNo
The required position of the page to insert, that means the page number for the newly inserted page. It must be a value greater than 0.

If the specified value is greater than the number of all pages in the loaded document, the new page is automatically inserted as the last page, as it is shown in the example below.

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.

Remarks
This method is only allowed for use with non-encrypted documents.

The newly inserted page is automatically set as the current page after the successful insertion.

Example
How to insert a blank page with the same page size as the first page to be the new first page and also to be the new last page of your document.
Dim caption As String = "Example: InsertPage"
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 > 0 Then
            status = gdpicturePDF.SelectPage(1)
            If status = GdPictureStatus.OK Then
                Dim pageHeight As Single = gdpicturePDF.GetPageHeight()
                status = gdpicturePDF.GetStat()
                If status = GdPictureStatus.OK Then
                    Dim pageWidth As Single = gdpicturePDF.GetPageWidth()
                    status = gdpicturePDF.GetStat()
                    If status = GdPictureStatus.OK Then
                        status = gdpicturePDF.InsertPage(pageWidth, pageHeight, 1)
                        If status = GdPictureStatus.OK Then
                            count = count + 1
                            Dim current As Integer = gdpicturePDF.GetCurrentPage()
                            status = gdpicturePDF.GetStat()
                            If status = GdPictureStatus.OK Then
                                MessageBox.Show("The page has been inserted successfully." + vbCrLf + "The currently selected page is page nr. " + current.ToString(), caption)
                            Else
                                MessageBox.Show("The page has been inserted successfully, but the GetCurrentPage() method has failed.")
                            End If
            
                            status = gdpicturePDF.InsertPage(pageWidth, pageHeight, count + 1)
                            If status = GdPictureStatus.OK Then
                                current = gdpicturePDF.GetCurrentPage()
                                status = gdpicturePDF.GetStat()
                                If status = GdPictureStatus.OK Then
                                    MessageBox.Show("The page has been inserted successfully." + vbCrLf + "The currently selected page is page nr. " + current.ToString(), caption)
                                Else
                                    MessageBox.Show("The page has been inserted successfully, but the GetCurrentPage() method has failed.")
                                End If
            
                                If gdpicturePDF.SaveToFile("test_InsertPage.pdf") = GdPictureStatus.OK Then
                                    MessageBox.Show("The pages have been inserted successfully and the file has been saved.", caption)
                                Else
                                    MessageBox.Show("The pages have been inserted successfully, but the file can't be saved.", caption)
                                End If
                            Else
                                MessageBox.Show("The InsertPage() method has failed with the status: " + status.ToString(), caption)
                                status = GdPictureStatus.OK
                            End If
                        Else
                            MessageBox.Show("The InsertPage() method has failed with the status: " + status.ToString(), caption)
                            status = GdPictureStatus.OK
                        End If
                    End If
                End If
            End If
        Else
            status = GdPictureStatus.InvalidParameter
        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: InsertPage";
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 > 0)
        {
            status = gdpicturePDF.SelectPage(1);
            if (status == GdPictureStatus.OK)
            {
                float pageHeight = gdpicturePDF.GetPageHeight();
                status = gdpicturePDF.GetStat();
                if (status == GdPictureStatus.OK)
                {
                    float pageWidth = gdpicturePDF.GetPageWidth();
                    status = gdpicturePDF.GetStat();
                    if (status == GdPictureStatus.OK)
                    {
                        status = gdpicturePDF.InsertPage(pageWidth, pageHeight, 1);
                        if (status == GdPictureStatus.OK)
                        {
                            count = count + 1;
                            int current = gdpicturePDF.GetCurrentPage();
                            status = gdpicturePDF.GetStat();
                            if (status == GdPictureStatus.OK)
                                MessageBox.Show("The page has been inserted successfully.\nThe currently selected page is page nr. " + current.ToString(), caption);
                            else
                                MessageBox.Show("The page has been inserted successfully, but the GetCurrentPage() method has failed.");
            
                            status = gdpicturePDF.InsertPage(pageWidth, pageHeight, count + 1);
                            if (status == GdPictureStatus.OK)
                            {
                                current = gdpicturePDF.GetCurrentPage();
                                status = gdpicturePDF.GetStat();
                                if (status == GdPictureStatus.OK)
                                    MessageBox.Show("The page has been inserted successfully.\nThe currently selected page is page nr. " + current.ToString(), caption);
                                else
                                    MessageBox.Show("The page has been inserted successfully, but the GetCurrentPage() method has failed.");
            
                                if (gdpicturePDF.SaveToFile("test_InsertPage.pdf") == GdPictureStatus.OK)
                                    MessageBox.Show("The pages have been inserted successfully and the file has been saved.", caption);
                                else
                                    MessageBox.Show("The pages have been inserted successfully, but the file can't be saved.", caption);
                            }
                            else
                            {
                                MessageBox.Show("The InsertPage() method has failed with the status: " + status.ToString(), caption);
                                status = GdPictureStatus.OK;
                            }
                        }
                        else
                        {
                            MessageBox.Show("The InsertPage() method has failed with the status: " + status.ToString(), caption);
                            status = GdPictureStatus.OK;
                        }
                    }
                }
            }
        }
        else
            status = GdPictureStatus.InvalidParameter;
    }
    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();
See Also