The stream object handling data of the first PDF document to merge. It must be initialized before it can be sent into this method and it should remain open for subsequent use.
The stream object handling data of the second PDF document to merge. It must be initialized before it can be sent into this method and it should remain open for subsequent use.
The destination stream. This Stream object must be initialized before it can be sent into this method and it should remain open for subsequent use. Further the destination stream should be open for writing.

Please ensure that the destination stream file path differs from both source streams (file paths).

Example





In This Topic
GdPicture14 Namespace / GdPicturePDF Class / Merge2Documents Method / Merge2Documents(Stream,Stream,Stream) Method

Merge2Documents(Stream,Stream,Stream) Method

In This Topic
Merges two PDF documents stored in the previously instantiated Stream objects according to what you have specified. The only supported file format for these input streams is the PDF format. The resulting PDF document is also saved to a Stream object you have specified.

Please see also the Merge2Documents(GdPicturePDF,GdPicturePDF) method for more details.

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

Syntax
'Declaration
 
Public Overloads Function Merge2Documents( _
   ByVal SrcDoc1 As Stream, _
   ByVal SrcDoc2 As Stream, _
   ByVal DstDoc As Stream _
) As GdPictureStatus
public GdPictureStatus Merge2Documents( 
   Stream SrcDoc1,
   Stream SrcDoc2,
   Stream DstDoc
)
public function Merge2Documents( 
    SrcDoc1: Stream;
    SrcDoc2: Stream;
    DstDoc: Stream
): GdPictureStatus; 
public function Merge2Documents( 
   SrcDoc1 : Stream,
   SrcDoc2 : Stream,
   DstDoc : Stream
) : GdPictureStatus;
public: GdPictureStatus Merge2Documents( 
   Stream* SrcDoc1,
   Stream* SrcDoc2,
   Stream* DstDoc
) 
public:
GdPictureStatus Merge2Documents( 
   Stream^ SrcDoc1,
   Stream^ SrcDoc2,
   Stream^ DstDoc
) 

Parameters

SrcDoc1
The stream object handling data of the first PDF document to merge. It must be initialized before it can be sent into this method and it should remain open for subsequent use.
SrcDoc2
The stream object handling data of the second PDF document to merge. It must be initialized before it can be sent into this method and it should remain open for subsequent use.
DstDoc
The destination stream. This Stream object must be initialized before it can be sent into this method and it should remain open for subsequent use. Further the destination stream should be open for writing.

Please ensure that the destination stream file path differs from both source streams (file paths).

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
Please note that both source streams together with the destination stream should remain open and can only be closed/disposed of by the user. Likewise it is required, that the destination stream (file path) differs from both source stream (file paths).

You don't need to load any document within the GdPicturePDF object you are going to use. You can simply use it as an empty wrapper object, as it is shown in the example below.

Example
How to merge two PDF documents stored in the instantiated streams into a destination stream and how to display the resulting PDF document in the GdViewer object.
Using gdpicturePDF As New GdPicturePDF()
    Dim doc1 As System.IO.Stream = New System.IO.FileStream("test1.pdf", System.IO.FileMode.Open)
    Dim doc2 As System.IO.Stream = New System.IO.FileStream("test2.pdf", System.IO.FileMode.Open)
    Dim mergedDoc As System.IO.Stream = New System.IO.MemoryStream()
    Dim status As GdPictureStatus = gdpicturePDF.Merge2Documents(doc1, doc2, mergedDoc)
    If status = GdPictureStatus.OK Then
        MessageBox.Show("Both documents have been successfully merged.", "Example: Merge2Documents")
    Else
        MessageBox.Show("The Merge2Documents() method has failed with the status: " + status.ToString(), "Example: Merge2Documents")
    End If
    Dim oViewer As New GdViewer()
    oViewer.DisplayFromStream(mergedDoc)
    oViewer.Dispose()
    doc1.Dispose()
    doc2.Dispose()
    mergedDoc.Dispose()
End Using
using (GdPicturePDF gdpicturePDF = new GdPicturePDF())
{
    System.IO.Stream doc1 = new System.IO.FileStream("test1.pdf", System.IO.FileMode.Open);
    System.IO.Stream doc2 = new System.IO.FileStream("test2.pdf", System.IO.FileMode.Open);
    System.IO.Stream mergedDoc = new System.IO.MemoryStream();
    GdPictureStatus status = gdpicturePDF.Merge2Documents(doc1, doc2, mergedDoc);
    if (status == GdPictureStatus.OK)
    {
        MessageBox.Show("Both documents have been successfully merged.", "Example: Merge2Documents");
    }
    else
    {
        MessageBox.Show("The Merge2Documents() method has failed with the status: " + status.ToString(), "Example: Merge2Documents");
    }
    GdViewer oViewer = new GdViewer();
    oViewer.DisplayFromStream(mergedDoc);
    oViewer.Dispose();
    doc1.Dispose();
    doc2.Dispose();
    mergedDoc.Dispose();
}
See Also