SaveToStream(Stream,Boolean,Boolean) Method
                In This Topic
            
            Packs, linearizes and saves the currently loaded PDF document to an instantiated Stream object according to what you have specified.
            
            
            Syntax
            
            
            
            
            'Declaration
 
Public Overloads Function SaveToStream( _
   ByVal  As Stream, _
   ByVal  As Boolean, _
   ByVal  As Boolean _
) As GdPictureStatus
             
        
            
            public GdPictureStatus SaveToStream( 
   Stream ,
   bool ,
   bool 
)
             
        
            
            public function SaveToStream( 
    : Stream;
    : Boolean;
    : Boolean
): GdPictureStatus; 
             
        
            
            public function SaveToStream( 
    : Stream,
    : boolean,
    : boolean
) : GdPictureStatus;
             
        
            
            public: GdPictureStatus SaveToStream( 
   Stream* ,
   bool ,
   bool 
) 
             
        
            
            public:
GdPictureStatus SaveToStream( 
   Stream^ ,
   bool ,
   bool 
) 
             
        
             
        
            Parameters
- Stream
- A Stream object where the currently loaded PDF document will be saved to.
             This Stream object must be initialized before it can be sent into this method and it should remain open for subsequent use.
- PackDocument
- Specifies if the toolkit has to pack the current document before the save process to reduce its size. 
Set this parameter to true if you want to pack the PDF document before saving. Please note that the whole saving process can be as a result slower with some documents. If you set this parameter to false, the PDF document will remain unpacked after the save process. 
- Linearize
- Specifies if the PDF document should be linearized when saving, that means if the PDF document should enable Fast Web View mode. 
Set this parameter to true to enable optimized save for Fast Web View mode. If you set this parameter to false, your PDF will not be optimized for Fast Web View mode when saving. 
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 linearize and save the PDF document using a stream.
             
             
             
             
    
	
		Dim caption As String = "Example: SaveToStream"
Dim gdpicturePDF As New GdPicturePDF()
If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
    gdpicturePDF.EnableCompression(True)
    If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
        GoTo [error]
    End If
            
    Dim oFileStream As New System.IO.FileStream("test_Stream_compressed_pack_unlinearize.pdf", System.IO.FileMode.Create)
    If gdpicturePDF.SaveToStream(oFileStream, True, False) = GdPictureStatus.OK Then
        MessageBox.Show("Saving the file to a stream with compression, with packing but without linearization has been successful.", caption)
    End If
    oFileStream.Dispose()
            
    oFileStream = New System.IO.FileStream("test_Stream_compressed_pack_linearize.pdf", System.IO.FileMode.Create)
    If gdpicturePDF.SaveToStream(oFileStream, True, True) = GdPictureStatus.OK Then
        MessageBox.Show("Saving the file to a stream with compression, with packing and with linearization has been successful.", caption)
    End If
    oFileStream.Dispose()
    gdpicturePDF.CloseDocument()
            
    oFileStream = New System.IO.FileStream("test_Stream_compressed_pack_unlinearize.pdf", System.IO.FileMode.Open)
    If gdpicturePDF.LoadFromStream(oFileStream, False) = GdPictureStatus.OK Then
        Dim isLinearized As Boolean = gdpicturePDF.IsLinearized()
        If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
            If isLinearized Then
                MessageBox.Show("This file is linearized.", caption)
            Else
                'This should be the correct case.
                MessageBox.Show("This file is not linearized.", caption)
            End If
        End If
    End If
    oFileStream.Dispose()
    gdpicturePDF.CloseDocument()
            
    oFileStream = New System.IO.FileStream("test_Stream_compressed_pack_linearize.pdf", System.IO.FileMode.Open)
    If gdpicturePDF.LoadFromStream(oFileStream, False) = GdPictureStatus.OK Then
        Dim isLinearized As Boolean = gdpicturePDF.IsLinearized()
        If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
            If isLinearized Then
                'This should be the correct case.
                MessageBox.Show("This file is linearized.", caption)
            Else
                MessageBox.Show("This file is not linearized.", caption)
            End If
        End If
    End If
    oFileStream.Dispose()
Else
    MessageBox.Show("The file can't be loaded.", caption)
End If
[error]:
gdpicturePDF.Dispose()
	 
	
		string caption = "Example: SaveToStream";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
{
    gdpicturePDF.EnableCompression(true);
    if (gdpicturePDF.GetStat() != GdPictureStatus.OK) goto error;
            
    System.IO.FileStream oFileStream = new System.IO.FileStream("test_Stream_compressed_pack_unlinearize.pdf", System.IO.FileMode.Create);
    if (gdpicturePDF.SaveToStream(oFileStream, true, false) == GdPictureStatus.OK)
    {
        MessageBox.Show("Saving the file to a stream with compression, with packing but without linearization has been successful.", caption);
    }
    oFileStream.Dispose();
            
    oFileStream = new System.IO.FileStream("test_Stream_compressed_pack_linearize.pdf", System.IO.FileMode.Create);
    if (gdpicturePDF.SaveToStream(oFileStream, true, true) == GdPictureStatus.OK)
    {
        MessageBox.Show("Saving the file to a stream with compression, with packing and with linearization has been successful.", caption);
    }
    oFileStream.Dispose();
    gdpicturePDF.CloseDocument();
            
    oFileStream = new System.IO.FileStream("test_Stream_compressed_pack_unlinearize.pdf", System.IO.FileMode.Open);
    if (gdpicturePDF.LoadFromStream(oFileStream, false) == GdPictureStatus.OK)
    {
        bool isLinearized = gdpicturePDF.IsLinearized();
        if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
        {
            if (isLinearized)
            {
                MessageBox.Show("This file is linearized.", caption);
            }
            else
            {
                //This should be the correct case.
                MessageBox.Show("This file is not linearized.", caption);
            }
        }
    }
    oFileStream.Dispose();
    gdpicturePDF.CloseDocument();
            
    oFileStream = new System.IO.FileStream("test_Stream_compressed_pack_linearize.pdf", System.IO.FileMode.Open);
    if (gdpicturePDF.LoadFromStream(oFileStream, false) == GdPictureStatus.OK)
    {
        bool isLinearized = gdpicturePDF.IsLinearized();
        if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
        {
            if (isLinearized)
            {
                //This should be the correct case.
                MessageBox.Show("This file is linearized.", caption);
            }
            else
            {
                MessageBox.Show("This file is not linearized.", caption);
            }
        }
    }
    oFileStream.Dispose();
}
else
{
    MessageBox.Show("The file can't be loaded.", caption);
}
error:
gdpicturePDF.Dispose();
	 
	
 
Example
How to linearize and save the PDF document using a stream.
             
             Dim caption As String = "Example: SaveToStream"
             Dim gdpicturePDF As New GdPicturePDF()
             If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
                 gdpicturePDF.EnableCompression(True)
                 If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
                     GoTo [error]
                 End If
            
                 Dim oFileStream As New System.IO.FileStream("test_Stream_compressed_pack_unlinearize.pdf", System.IO.FileMode.Create)
                 If gdpicturePDF.SaveToStream(oFileStream, True, False) = GdPictureStatus.OK Then
                     MessageBox.Show("Saving the file to a stream with compression, with packing but without linearization has been successful.", caption)
                 End If
                 oFileStream.Dispose()
            
                 oFileStream = New System.IO.FileStream("test_Stream_compressed_pack_linearize.pdf", System.IO.FileMode.Create)
                 If gdpicturePDF.SaveToStream(oFileStream, True, True) = GdPictureStatus.OK Then
                     MessageBox.Show("Saving the file to a stream with compression, with packing and with linearization has been successful.", caption)
                 End If
                 oFileStream.Dispose()
                 gdpicturePDF.CloseDocument()
            
                 oFileStream = New System.IO.FileStream("test_Stream_compressed_pack_unlinearize.pdf", System.IO.FileMode.Open)
                 If gdpicturePDF.LoadFromStream(oFileStream, False) = GdPictureStatus.OK Then
                     Dim isLinearized As Boolean = gdpicturePDF.IsLinearized()
                     If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                         If isLinearized Then
                             MessageBox.Show("This file is linearized.", caption)
                         Else
                             'This should be the correct case.
                             MessageBox.Show("This file is not linearized.", caption)
                         End If
                     End If
                 End If
                 oFileStream.Dispose()
                 gdpicturePDF.CloseDocument()
            
                 oFileStream = New System.IO.FileStream("test_Stream_compressed_pack_linearize.pdf", System.IO.FileMode.Open)
                 If gdpicturePDF.LoadFromStream(oFileStream, False) = GdPictureStatus.OK Then
                     Dim isLinearized As Boolean = gdpicturePDF.IsLinearized()
                     If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                         If isLinearized Then
                             'This should be the correct case.
                             MessageBox.Show("This file is linearized.", caption)
                         Else
                             MessageBox.Show("This file is not linearized.", caption)
                         End If
                     End If
                 End If
                 oFileStream.Dispose()
             Else
                 MessageBox.Show("The file can't be loaded.", caption)
             End If
             [error]:
             gdpicturePDF.Dispose()
             
             string caption = "Example: SaveToStream";
             GdPicturePDF gdpicturePDF = new GdPicturePDF();
             if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
             {
                 gdpicturePDF.EnableCompression(true);
                 if (gdpicturePDF.GetStat() != GdPictureStatus.OK) goto error;
            
                 System.IO.FileStream oFileStream = new System.IO.FileStream("test_Stream_compressed_pack_unlinearize.pdf", System.IO.FileMode.Create);
                 if (gdpicturePDF.SaveToStream(oFileStream, true, false) == GdPictureStatus.OK)
                 {
                     MessageBox.Show("Saving the file to a stream with compression, with packing but without linearization has been successful.", caption);
                 }
                 oFileStream.Dispose();
            
                 oFileStream = new System.IO.FileStream("test_Stream_compressed_pack_linearize.pdf", System.IO.FileMode.Create);
                 if (gdpicturePDF.SaveToStream(oFileStream, true, true) == GdPictureStatus.OK)
                 {
                     MessageBox.Show("Saving the file to a stream with compression, with packing and with linearization has been successful.", caption);
                 }
                 oFileStream.Dispose();
                 gdpicturePDF.CloseDocument();
            
                 oFileStream = new System.IO.FileStream("test_Stream_compressed_pack_unlinearize.pdf", System.IO.FileMode.Open);
                 if (gdpicturePDF.LoadFromStream(oFileStream, false) == GdPictureStatus.OK)
                 {
                     bool isLinearized = gdpicturePDF.IsLinearized();
                     if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                     {
                         if (isLinearized)
                         {
                             MessageBox.Show("This file is linearized.", caption);
                         }
                         else
                         {
                             //This should be the correct case.
                             MessageBox.Show("This file is not linearized.", caption);
                         }
                     }
                 }
                 oFileStream.Dispose();
                 gdpicturePDF.CloseDocument();
            
                 oFileStream = new System.IO.FileStream("test_Stream_compressed_pack_linearize.pdf", System.IO.FileMode.Open);
                 if (gdpicturePDF.LoadFromStream(oFileStream, false) == GdPictureStatus.OK)
                 {
                     bool isLinearized = gdpicturePDF.IsLinearized();
                     if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
                     {
                         if (isLinearized)
                         {
                             //This should be the correct case.
                             MessageBox.Show("This file is linearized.", caption);
                         }
                         else
                         {
                             MessageBox.Show("This file is not linearized.", caption);
                         }
                     }
                 }
                 oFileStream.Dispose();
             }
             else
             {
                 MessageBox.Show("The file can't be loaded.", caption);
             }
             error:
             gdpicturePDF.Dispose();
             
            
            
            See Also