GdPicture.NET.14
GdPicture14 Namespace / AnnotationManager Class / InitFromStream Method / InitFromStream(Stream,String) Method
A System.IO.Stream object. This object must be properly initialized before it can be sent into this method and it must be disposed of by the user as well.
The file name of the document, that is stored in the Stream parameter, for example myfile.svg. The toolkit will automatically recognize the document format based on the file name to be able to load the required file.
Example





In This Topic
InitFromStream(Stream,String) Method
In This Topic
Initializes the current AnnotationManager object from an instantiated Stream object according to what you have specified. The document previously handled by this AnnotationManager will automatically close.

This method is useful for files, that have no header information in their internal structure, like text files or .svg files, as you can specify their file name to allow the toolkit with certainty to recognize the document format of the file to load.

All document formats currently supported by the toolkit are listed here.

Be aware that the AnnotationManager object only handles GdPicture/XMP annotations contained in the source document.

Syntax
'Declaration
 
Public Overloads Function InitFromStream( _
   ByVal Stream As Stream, _
   ByVal FileName As String _
) As GdPictureStatus
public GdPictureStatus InitFromStream( 
   Stream Stream,
   string FileName
)
public function InitFromStream( 
    Stream: Stream;
    FileName: String
): GdPictureStatus; 
public function InitFromStream( 
   Stream : Stream,
   FileName : String
) : GdPictureStatus;
public: GdPictureStatus InitFromStream( 
   Stream* Stream,
   string* FileName
) 
public:
GdPictureStatus InitFromStream( 
   Stream^ Stream,
   String^ FileName
) 

Parameters

Stream
A System.IO.Stream object. This object must be properly initialized before it can be sent into this method and it must be disposed of by the user as well.
FileName
The file name of the document, that is stored in the Stream parameter, for example myfile.svg. The toolkit will automatically recognize the document format based on the file name to be able to load the required file.

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 requires the Annotations component to run.

Example
How to initialize the AnnotationManager object from a SVG file using a stream.
Dim annotationManager As AnnotationManager = New AnnotationManager()
Dim filename As String = "image.svg"
Dim file As System.IO.Stream = New System.IO.FileStream(filename, System.IO.FileMode.Open)
If (annotationManager.InitFromStream(file, filename) = GdPictureStatus.OK) AndAlso
   (annotationManager.PageCount > 0) AndAlso (annotationManager.SelectPage(1) = GdPictureStatus.OK) Then
    Dim stamp As GdPicture14.Annotations.AnnotationRubberStamp = annotationManager.AddRubberStampAnnot(Color.Red, 0.5F, 0.5F, 2, 1, "APPROVED")
    If stamp IsNot Nothing Then
        stamp.Rotation = 20
        If (annotationManager.SaveAnnotationsToPage() = GdPictureStatus.OK) AndAlso
           (annotationManager.BurnAnnotationsToPage(True) = GdPictureStatus.OK) AndAlso
           (annotationManager.SaveDocumentToTIFF("image_approved.tif", TiffCompression.TiffCompressionAUTO) = GdPictureStatus.OK) Then
            MessageBox.Show("Finished successfully!", "AnnotationManager.InitFromStream")
        Else
            MessageBox.Show("The file can't be saved. Status: " + annotationManager.GetStat().ToString(), "AnnotationManager.InitFromStream")
        End If
        stamp.Dispose()
    Else
        MessageBox.Show("The rubber stamp annotation can't be created. Status: " + annotationManager.GetStat().ToString(), "AnnotationManager.InitFromStream")
    End If
    annotationManager.Close()
Else
    MessageBox.Show("The AnnotationManager can't be properly initialized. Status: " + annotationManager.GetStat().ToString(), "AnnotationManager.InitFromStream")
End If
annotationManager.Dispose()
file.Dispose()
AnnotationManager annotationManager = new AnnotationManager();
String filename = "image.svg";
System.IO.Stream file = new System.IO.FileStream(filename, System.IO.FileMode.Open);
if ((annotationManager.InitFromStream(file, filename) == GdPictureStatus.OK) &&
    (annotationManager.PageCount > 0) && (annotationManager.SelectPage(1) == GdPictureStatus.OK))
{
    GdPicture14.Annotations.AnnotationRubberStamp stamp = annotationManager.AddRubberStampAnnot(Color.Red, 0.5f, 0.5f, 2, 1, "APPROVED");
    if (stamp != null)
    {
        stamp.Rotation = 20;
        if ((annotationManager.SaveAnnotationsToPage() == GdPictureStatus.OK) &&
            (annotationManager.BurnAnnotationsToPage(true) == GdPictureStatus.OK) &&
            (annotationManager.SaveDocumentToTIFF("image_approved.tif", TiffCompression.TiffCompressionAUTO) == GdPictureStatus.OK))
            MessageBox.Show("Finished successfully!", "AnnotationManager.InitFromStream");
        else
            MessageBox.Show("The file can't be saved. Status: " + annotationManager.GetStat().ToString(), "AnnotationManager.InitFromStream");
        stamp.Dispose();
    }
    else
        MessageBox.Show("The rubber stamp annotation can't be created. Status: " + annotationManager.GetStat().ToString(), "AnnotationManager.InitFromStream");
    annotationManager.Close();
}
else
    MessageBox.Show("The AnnotationManager can't be properly initialized. Status: " + annotationManager.GetStat().ToString(), "AnnotationManager.InitFromStream");
annotationManager.Dispose();
file.Dispose();
See Also