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 GdPicturePDF.Merge2Documents 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 As Stream, _
ByVal As Stream, _
ByVal As Stream _
) As GdPictureStatus
public GdPictureStatus Merge2Documents(
Stream ,
Stream ,
Stream
)
public function Merge2Documents(
: Stream;
: Stream;
: Stream
): GdPictureStatus;
public function Merge2Documents(
: Stream,
: Stream,
: Stream
) : GdPictureStatus;
public: GdPictureStatus Merge2Documents(
Stream* ,
Stream* ,
Stream*
)
public:
GdPictureStatus Merge2Documents(
Stream^ ,
Stream^ ,
Stream^
)
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.
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();
}
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