Save a file from the annotation manager in C#
Nutrient .NET SDK (formerly GdPicture.NET) enables you to save GdPicture XMP annotations located in a file with the SaveAnnotationsToXMP and SaveAnnotationsToXMPEx methods. They enable you to do the following:
- Save annotations from an image.
 - Save annotations from a specific page of a multipage file.
 - Save annotations from all pages of a multipage file.
 
Saving annotations from an image
To save GdPicture XMP annotations created with the AnnotationManager class from an image to an XML file or a Stream object, use the SaveAnnotationsToXMP method. It uses the file path as a string or a Stream object as its parameter.
To save annotations from an image, 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();// Save the annotation to an XML file.annotationManager.SaveAnnotationsToXMP(@"C:\temp\output.xml");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()    ' Save the annotation to an XML file.    annotationManager.SaveAnnotationsToXMP("C:\temp\output.xml")End UsingSaving annotations from a specific page
To save the GdPicture XMP annotations created with the AnnotationManager class from a specific document page to an XML file or a Stream object, use the SaveAnnotationsToXMP method. It uses the file path as a string, or a Stream object as its parameter.
Use the SelectPage method for multipage files like PDF documents and TIFF images.
To save annotations on the first page of a PDF document, use the following code:
using AnnotationManager annotationManager= new AnnotationManager();// Load a PDF document to the `AnnotationManager` object.annotationManager.InitFromFile(@"C:\temp\source.pdf");// Select the first page.annotationManager.SelectPage(1);// 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();// Save the annotation to an XML file.annotationManager.SaveAnnotationsToXMP(@"C:\temp\output.xml");Using annotationManager As AnnotationManager = New AnnotationManager()    ' Load a PDF document to the `AnnotationManager` object.    annotationManager.InitFromFile("C:\temp\source.pdf")    ' Select the first page.    annotationManager.SelectPage(1)    ' 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()    ' Save the annotation to an XML file.    annotationManager.SaveAnnotationsToXMP("C:\temp\output.xml")End UsingSaving annotations from all pages
To save the GdPicture XMP annotations created with the AnnotationManager class from all pages of a multipage file to an XML file or a Stream object, use the SaveAnnotationsToXMPEx method. It uses the file path as a string or a Stream object as its parameter.
To save annotations from all pages of a PDF document, use the following code:
using AnnotationManager annotationManager= new AnnotationManager();// Load a PDF document to the `AnnotationManager` object.annotationManager.InitFromFile(@"C:\temp\source.pdf");// 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();// Save the annotation to an XML file.annotationManager.SaveAnnotationsToXMPEx(@"C:\temp\output.xml");Using annotationManager As AnnotationManager = New AnnotationManager()    ' Load a PDF document to the `AnnotationManager` object.    annotationManager.InitFromFile("C:\temp\source.pdf")    ' 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()    ' Save the annotation to an XML file.    annotationManager.SaveAnnotationsToXMPEx("C:\temp\output.xml")End Using