Load a stream for the annotation manager in C#

Stream

To load a Stream object to the AnnotationManager object, use the InitFromStream method. This method requires the following parameters:

  • Stream — The file stored in a stream object.
  • FileName — Optional: The full path to a file with the same format as the file in the stream object. The extension of this file helps your program recognize the document format of the file used in the stream object. Use this parameter when the file has no header information in its internal structure (for example, text or SVG image files).

The list of supported file formats is available on the Supported File Types page.

The AnnotationManager object only handles GdPicture and XMP annotations contained in the source document.

To load a Stream object to the AnnotationManager object, use the following code:

using AnnotationManager annotationManager = new AnnotationManager();
// Create a `Stream` object from a text file.
Stream file = new FileStream(@"C:\temp\source.txt", FileMode.Open);
// Load the stream to the `AnnotationManager` object.
annotationManager.InitFromStream(file, @"C:\temp\source.txt");
// Create an `AnnotationRubberStamp` object.
GdPicture14.Annotations.AnnotationRubberStamp stamp;
// Add the stamp to the `AnnotationManager` object.
stamp = annotationManager.AddRubberStampAnnot(new GdPictureColor(255, 0, 0),
0.5f, 0.5f, 2, 1, "APPROVED");
stamp.Rotation = 20;
// Save the annotation to the `AnnotationManager` object.
annotationManager.SaveAnnotationsToPage();
// Flatten the annotation into the image.
annotationManager.BurnAnnotationsToPage(false);
// Save the image with the annotation.
annotationManager.SaveDocumentToJPEG(@"C:\temp\output.jpg", 100);