The optional unique number (id) of this annotation object.
public string ObjectNumber {get; set;}
Optional unique number (ID) of this annotation object. The default value is null.
Annotations can be loaded from a PDF using PDFDocument.ParsePages and specifying the PDFParsePagesOptions.Annotations option. If the PDF object contains annotations, then will be set in each Annotations of each PDFDocumentPage in the document.
Annotations can be saved to a PDF file using PDFFile.WriteAnnotations. This method accepts a list of PDFAnnotation-derived objects to store into a PDF.
The PDF specification dictates that each annotation object must contain a unique ID called the object number. When loading annotation objects, the value is set into the ObjectNumber value.
When saving annotations into a PDF file, the object number can be left empty (null), and LEADTOOLS will generate a unique ID for each object during the save process. This is enough if there is no special relationship between the objects. Internally, the framework will assign each object a unique ID prior to storing it to the PDF.
If a relationship is desired, such as parent/child or group, then the user is responsible for setting unique object numbers (IDs) to the objects. These IDs will then be used by LEADTOOLS to find and check the required objects during the save process, but will still be replaced by auto-generated unique IDs. It is, however, the user's responsibility to ensure that the IDs passed are:
An exception is thrown if an ID does not meet these conditions.
This example shows how to use ObjectNumber to store annotation objects (with and without replies) into a PDF file.
using Leadtools.WinForms;
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Controls;
using Leadtools.Drawing;
using Leadtools.ImageProcessing;
using Leadtools.Pdf;
using Leadtools.Svg;
public void AnnotationsReplyParentChildTest()
{
string sourceFile = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf");
string targetFile = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools_with_rectangle_reply.pdf");
// Copy the source to target
if (File.Exists(targetFile))
{
File.SetAttributes(targetFile, File.GetAttributes(targetFile) & ~FileAttributes.ReadOnly);
File.Delete(targetFile);
}
File.Copy(sourceFile, targetFile, true);
File.SetAttributes(targetFile, File.GetAttributes(targetFile) & ~FileAttributes.ReadOnly);
var annotations = new List<PDFAnnotation>();
// Add a rectangle and a reply to it
const string myRectangle = "myRectangle";
const string myReply = "myReply";
// Create dashed red pen with width of 2
var pen = new PDFPen();
pen.Color = RasterColor.FromKnownColor(RasterKnownColor.Red);
pen.PenStyle = PDFPen.Dashed;
pen.Width = 2;
// Create red solid brush
var brush = new PDFBrush();
brush.BrushStyle = PDFBrush.Solid;
brush.Color = RasterColor.FromKnownColor(RasterKnownColor.Red);
var rectObj = new PDFRectangleAnnotation();
rectObj.PageNumber = 1;
rectObj.Pen = pen;
rectObj.Brush = brush;
var rect = new PDFRect(72, 72, 144, 108);
rectObj.Bounds = rect;
rectObj.Transparency = 1;
// Set the object number to a unique value, here we call it parent1. Note that this is
// will be used when storing the objects inside the PDF and the object id (or number)
// will be replaced by a unique value during the save process.
rectObj.ObjectNumber = myRectangle;
annotations.Add(rectObj);
// Add an opened note that is a child of the rectangle
var noteObj1 = new PDFNoteAnnotation();
noteObj1.PageNumber = 1;
noteObj1.Content = "Reply to rect";
noteObj1.Point = new PDFPoint(72, 72);
noteObj1.Color = RasterColor.FromKnownColor(RasterKnownColor.Yellow);
noteObj1.Open = false;
// We must give it a unique name, again will be replaced by the framework.
noteObj1.ObjectNumber = myReply;
// And set the object we are replying to, in this case, the rectangle
noteObj1.ParentObjectNumber = rectObj.ObjectNumber;
annotations.Add(noteObj1);
// Add an ellipse, with no note
var ellipseObj = new PDFEllipseAnnotation();
ellipseObj.PageNumber = 1;
ellipseObj.Pen = pen;
ellipseObj.Brush = brush;
rect = new PDFRect(216, 72, 288, 108);
ellipseObj.Center = new PDFPoint(rect.Left + rect.Right / 2, rect.Top + rect.Bottom / 2);
ellipseObj.HorizontalRadius = rect.Right - rect.Left;
ellipseObj.VerticalRadius = rect.Bottom - rect.Top;
ellipseObj.Transparency = 1;
// Note that since we will not add a reply to this annotation object, we do not
// have to set the value of ObjectNumber to anything and leave it as the default
// of null. The framework will replace it with a unique value during the save
// process.
//ellipseObj.ObjectNumber = null;
annotations.Add(ellipseObj);
// Add an opened note that is a not a child of any objects.
var noteObj2 = new PDFNoteAnnotation();
noteObj2.PageNumber = 1;
noteObj2.Content = "No parent";
noteObj2.Point = new PDFPoint(216, 72);
noteObj2.Color = RasterColor.FromKnownColor(RasterKnownColor.Yellow);
noteObj2.Open = true;
// Again, since we do not need to associate this object with any other there is no
// need to set its nor its parent ID
//noteObj2.ObjectNumber = null;
//noteObj2.ParentObjectNumber = null;
annotations.Add(noteObj2);
// Save the PDF file
var pdfFile = new PDFFile(targetFile);
pdfFile.WriteAnnotations(annotations, null);
Console.WriteLine("PDF file with annotations created in\n{0}", targetFile);
// Open the created PDF in Adobe Acrobat and it should contain the following:
// - Dashed red rectangle object.
// - Closed reply to the rectangle with "Reply to rect" content. This should show as a note in the rectangle object.
// - Dashed red ellipse object.
// - Open yellow stand-alone note object with "No parent" content.
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";
}