Load any file for the annotation manager in C#
To load a supported file into the AnnotationManager class, use the InitFromFile method.
InitFromFile takes a full file path and returns a GdPictureStatus, which should be checked before working with annotations.
The list of supported formats is available on the supported file types page.
The AnnotationManager only handles GdPicture annotations and XMP annotations contained in the source document.
To load a file into AnnotationManager, add an annotation, and save the result, use the following code:
In some cross-platform GdPicture.API (net8.0) setups, AnnotationManager.AddRubberStampAnnot(...) expects GdPicture14.Imaging.GdPictureColor rather than System.Drawing.Color. If Color.Red from System.Drawing causes a type mismatch, use a GdPictureColor value instead (for example, GdPictureColor.Red or GdPicture14.Imaging.GdPictureColor.Red) or explicitly construct a GdPictureColor.
using GdPicture14;using GdPicture14.Annotations;using System;using System.Drawing;
using AnnotationManager annotationManager = new AnnotationManager();
GdPictureStatus status = annotationManager.InitFromFile(@"C:\temp\source.jpg");if (status != GdPictureStatus.OK){ Console.WriteLine($"InitFromFile failed: {status}"); return;}
AnnotationRubberStamp stamp = annotationManager.AddRubberStampAnnot( Color.Red, 0.5f, 0.5f, 2, 1, "APPROVED");
if (stamp == null){ Console.WriteLine("AddRubberStampAnnot failed."); return;}
stamp.Rotation = 20;
status = annotationManager.SaveAnnotationsToPage();if (status != GdPictureStatus.OK){ Console.WriteLine($"SaveAnnotationsToPage failed: {status}"); return;}
status = annotationManager.BurnAnnotationsToPage(false);if (status != GdPictureStatus.OK){ Console.WriteLine($"BurnAnnotationsToPage failed: {status}"); return;}
status = annotationManager.SaveDocumentToJPEG(@"C:\temp\output.jpg", 100);if (status != GdPictureStatus.OK){ Console.WriteLine($"SaveDocumentToJPEG failed: {status}");}Imports GdPicture14Imports GdPicture14.AnnotationsImports System.Drawing
Using annotationManager As New AnnotationManager() Dim status As GdPictureStatus = annotationManager.InitFromFile("C:\temp\source.jpg") If status <> GdPictureStatus.OK Then Console.WriteLine($"InitFromFile failed: {status}") Return End If
Dim stamp As AnnotationRubberStamp = annotationManager.AddRubberStampAnnot( Color.Red, 0.5F, 0.5F, 2, 1, "APPROVED")
If stamp Is Nothing Then Console.WriteLine("AddRubberStampAnnot failed.") Return End If
stamp.Rotation = 20
status = annotationManager.SaveAnnotationsToPage() If status <> GdPictureStatus.OK Then Console.WriteLine($"SaveAnnotationsToPage failed: {status}") Return End If
status = annotationManager.BurnAnnotationsToPage(False) If status <> GdPictureStatus.OK Then Console.WriteLine($"BurnAnnotationsToPage failed: {status}") Return End If
status = annotationManager.SaveDocumentToJPEG("C:\temp\output.jpg", 100) If status <> GdPictureStatus.OK Then Console.WriteLine($"SaveDocumentToJPEG failed: {status}") End IfEnd Using