To load any type of file to the AnnotationManager
object, use the InitFromFile
method. This method requires the full path to a file as its parameter.
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 an image file to the AnnotationManager
object, use the following code:
using AnnotationManager annotationManager= new AnnotationManager(); // Load an image to the `AnnotationManager` object. annotationManager.InitFromFile(@"C:\temp\source.jpg"); // Create an `AnnotationRubberStamp` object. GdPicture14.Annotations.AnnotationRubberStamp stamp; // Add the stamp to the `AnnotationManager` object. stamp = annotationManager.AddRubberStampAnnot(Color.Red, 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);
Using annotationManager As AnnotationManager = New AnnotationManager() ' Load an image to the `AnnotationManager` object. annotationManager.InitFromFile("C:\temp\source.jpg") ' Create an `AnnotationRubberStamp` object. Dim stamp As GdPicture14.Annotations.AnnotationRubberStamp ' Add the stamp to the `AnnotationManager` object. stamp = annotationManager.AddRubberStampAnnot(Color.Red, 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) End Using
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);
Using annotationManager As AnnotationManager = New AnnotationManager() ' Create a `Stream` object from a text file. Dim file As Stream = 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. Dim stamp As GdPicture14.Annotations.AnnotationRubberStamp ' 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) End Using
To load XMP or GdPicture annotations stored in an XML file or a Stream
object to the AnnotationManager
object, use the LoadAnnotationsFromXMP
method. As its parameter, this method requires either the full path of the XML file or a stream object containing XML data. This method replaces all annotations previously added to the AnnotationManager
object.
The
AnnotationManager
object only handles GdPicture and XMP annotations contained in the source document.
To apply annotations from a template image to another image, use the following code:
using AnnotationManager annotationManager = new AnnotationManager(); // Load the template image to the `AnnotationManager` object. annotationManager.InitFromFile(@"C:\temp\template.jpg"); // Save the annotations from the template image to an XML file. annotationManager.SaveAnnotationsToXMP(@"C:\temp\annotTemplate.xml"); // Load the source image to the `AnnotationManager` object. annotationManager.InitFromFile(@"C:\temp\source.jpg"); // Load the XML file with the annotations to the `AnnotationManager` object. annotationManager.LoadAnnotationsFromXMP(@"C:\temp\annotTemplate.xml"); // Flatten the annotations into the image. annotationManager.BurnAnnotationsToPage(false); // Save the image to a file. annotationManager.SaveDocumentToJPEG(@"C:\temp\output.jpg", 100);
Using annotationManager As AnnotationManager = New AnnotationManager() ' Load the template image to the `AnnotationManager` object. annotationManager.InitFromFile("C:\temp\template.jpg") ' Save the annotations from the template image to an XML file. annotationManager.SaveAnnotationsToXMP("C:\temp\annotTemplate.xml") ' Load the source image to the `AnnotationManager` object. annotationManager.InitFromFile("C:\temp\source.jpg") ' Load the XML file with the annotations to the `AnnotationManager` object. annotationManager.LoadAnnotationsFromXMP("C:\temp\annotTemplate.xml") ' Flatten the annotations into the image. annotationManager.BurnAnnotationsToPage(False) ' Save the image to a file. annotationManager.SaveDocumentToJPEG("C:\temp\output.jpg", 100) End Using