GdPicture.NET.14.API
GdPicture14 Namespace / GdPicturePDF Class / ClonePage Method / ClonePage(GdPicturePDF,Int32) Method
A GdPicturePDF object. The source PDF document, which contains the page you want to clone into the currently loaded PDF document.
The page number of a required page from the source document, which you want to clone into the current document. It must be a value from 1 to GdPicturePDF.GetPageCount of the source document.
Example





In This Topic
ClonePage(GdPicturePDF,Int32) Method
In This Topic
Clones a page specified by its page number located in the specified source PDF document into the currently loaded PDF document. The newly created page is added at the end of the current document as the last page and it is automatically selected as the current page.

Just to inform you, that the toolkit offers the adaptive file caching mechanism to significantly reduce memory usage while cloning large documents. The feature is available in both 32-bit and 64-bit mode by default.

This method can be useful when you need to merge multiple PDF documents into one destination document, as it is shown in the attached example. You can also benefit from this method when you need to split a large multipage PDF document into smaller separate PDF documents that will contain the required number of pages, please refer to this example of how to quickly achieve it.

Syntax
'Declaration
 
Public Overloads Function ClonePage( _
   ByVal FromPDF As GdPicturePDF, _
   ByVal PageNo As Integer _
) As GdPictureStatus
public GdPictureStatus ClonePage( 
   GdPicturePDF FromPDF,
   int PageNo
)
public function ClonePage( 
    FromPDF: GdPicturePDF;
    PageNo: Integer
): GdPictureStatus; 
public function ClonePage( 
   FromPDF : GdPicturePDF,
   PageNo : int
) : GdPictureStatus;
public: GdPictureStatus ClonePage( 
   GdPicturePDF* FromPDF,
   int PageNo
) 
public:
GdPictureStatus ClonePage( 
   GdPicturePDF^ FromPDF,
   int PageNo
) 

Parameters

FromPDF
A GdPicturePDF object. The source PDF document, which contains the page you want to clone into the currently loaded PDF document.
PageNo
The page number of a required page from the source document, which you want to clone into the current document. It must be a value from 1 to GdPicturePDF.GetPageCount of the source document.

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, both source and destination ones.

The newly created page is automatically set as the current page after successful cloning.

Example
How to merge two PDF documents into one destination document.
Dim caption As String = "Example: ClonePage"
Dim gdpicturePDF1 As New GdPicturePDF()
Dim gdpicturePDF2 As New GdPicturePDF()
If gdpicturePDF1.LoadFromFile("test1.pdf", False) = GdPictureStatus.OK Then
    If gdpicturePDF2.LoadFromFile("test2.pdf", False) = GdPictureStatus.OK Then
        Dim oGdPictureNewPDF As New GdPicturePDF()
        If oGdPictureNewPDF.NewPDF() = GdPictureStatus.OK Then
            Dim pageCount As Integer = gdpicturePDF1.GetPageCount()
            Dim status As GdPictureStatus = gdpicturePDF1.GetStat()
            If status = GdPictureStatus.OK Then
                For page As Integer = 1 To pageCount
                    status = oGdPictureNewPDF.ClonePage(gdpicturePDF1, page)
                    If status <> GdPictureStatus.OK Then
                        MessageBox.Show("The ClonePage() method has failed with the status: " + status.ToString() + vbCrLf + "Document: first    Page nr. " + page.ToString(), caption)
                        Exit For
                    End If
                Next
            Else
                MessageBox.Show("The GetPageCount() method for the first document has failed with the status: " + status.ToString(), caption)
            End If
            If status = GdPictureStatus.OK Then
                pageCount = gdpicturePDF2.GetPageCount()
                status = gdpicturePDF2.GetStat()
                If status = GdPictureStatus.OK Then
                    For page As Integer = 1 To pageCount
                        status = oGdPictureNewPDF.ClonePage(gdpicturePDF2, page)
                        If status <> GdPictureStatus.OK Then
                            MessageBox.Show("The ClonePage() method has failed with the status: " + status.ToString() + vbCrLf + "Document: second    Page nr. " + page.ToString(), caption)
                            Exit For
                        End If
                    Next
                Else
                    MessageBox.Show("The GetPageCount() method for the second document has failed with the status: " + status.ToString(), caption)
                End If
            End If
            If status = GdPictureStatus.OK Then
                Dim message As String = "The pages have been cloned successfully"
                If oGdPictureNewPDF.SaveToFile("test_ClonePage.pdf") = GdPictureStatus.OK Then
                    message = message + " and the file has been saved."
                Else
                    message = message + ", but the file can't be saved."
                End If
                MessageBox.Show(message, caption)
            End If
        Else
            MessageBox.Show("The destination file can't be created.", caption)
        End If
        oGdPictureNewPDF.Dispose()
    Else
        MessageBox.Show("The second file can't be loaded.", caption)
    End If
Else
    MessageBox.Show("The first file can't be loaded.", caption)
End If
gdpicturePDF1.Dispose()
gdpicturePDF2.Dispose()
string caption = "Example: ClonePage";
GdPicturePDF gdpicturePDF1 = new GdPicturePDF();
GdPicturePDF gdpicturePDF2 = new GdPicturePDF();
if (gdpicturePDF1.LoadFromFile("test1.pdf", false) == GdPictureStatus.OK)
{
    if (gdpicturePDF2.LoadFromFile("test2.pdf", false) == GdPictureStatus.OK)
    {
        GdPicturePDF oGdPictureNewPDF = new GdPicturePDF();
        if (oGdPictureNewPDF.NewPDF() == GdPictureStatus.OK)
        {
            int pageCount = gdpicturePDF1.GetPageCount();
            GdPictureStatus status = gdpicturePDF1.GetStat();
            if (status == GdPictureStatus.OK)
            {
                for (int page = 1; page <= pageCount; page++)
                {
                    status = oGdPictureNewPDF.ClonePage(gdpicturePDF1, page);
                    if (status != GdPictureStatus.OK)
                    {
                        MessageBox.Show("The ClonePage() method has failed with the status: " + status.ToString() + "\nDocument: first    Page nr. " + page.ToString(), caption);
                        break;
                    }
                }
            }
            else
                MessageBox.Show("The GetPageCount() method for the first document has failed with the status: " + status.ToString(), caption);
            if (status == GdPictureStatus.OK)
            {
                pageCount = gdpicturePDF2.GetPageCount();
                status = gdpicturePDF2.GetStat();
                if (status == GdPictureStatus.OK)
                {
                    for (int page = 1; page <= pageCount; page++)
                    {
                        status = oGdPictureNewPDF.ClonePage(gdpicturePDF2, page);
                        if (status != GdPictureStatus.OK)
                        {
                            MessageBox.Show("The ClonePage() method has failed with the status: " + status.ToString() + "\nDocument: second    Page nr. " + page.ToString(), caption);
                            break;
                        }
                    }
                }
                else
                    MessageBox.Show("The GetPageCount() method for the second document has failed with the status: " + status.ToString(), caption);
            }
            if (status == GdPictureStatus.OK)
            {
                string message = "The pages have been cloned successfully";
                if (oGdPictureNewPDF.SaveToFile("test_ClonePage.pdf") == GdPictureStatus.OK)
                    message = message + " and the file has been saved.";
                else
                    message = message + ", but the file can't be saved.";
                MessageBox.Show(message, caption);
            }
        }
        else
            MessageBox.Show("The destination file can't be created.", caption);
        oGdPictureNewPDF.Dispose();
    }
    else
        MessageBox.Show("The second file can't be loaded.", caption);
}
else
    MessageBox.Show("The first file can't be loaded.", caption);
gdpicturePDF1.Dispose();
gdpicturePDF2.Dispose();
See Also