←Select platform

ObjectNumber Property

Summary

The optional unique number (id) of this annotation object.

Syntax
C#
VB
C++
public string ObjectNumber {get; set;} 
Public Property ObjectNumber() As String 
   Get 
   Set 
public:  
   property String^ ObjectNumber 
   { 
      String^ get() 
      void set(String^ value) 
   } 

Property Value

Optional unique number (ID) of this annotation object. The default value is null.

Remarks

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:

  • Unique and do not conflict with each other
  • Should a parent/child relation be specified, the parent object ID must be set to a valid object in the annotations list.

An exception is thrown if an ID does not meet these conditions.

Example

This example shows how to use ObjectNumber to store annotation objects (with and without replies) into a PDF file.

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Controls; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
using Leadtools.Pdf; 
using Leadtools.Svg; 
using Leadtools.WinForms; 
 
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:\Users\Public\Documents\LEADTOOLS Images"; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Pdf 
Imports Leadtools.WinForms 
Imports Leadtools.Svg 
Imports Leadtools.ImageProcessing 
 
Public Sub AnnotationsReplyParentChildTest() 
   Dim sourceFile As String = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf") 
   Dim targetFile As String = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools_with_rectangle_reply.pdf") 
 
   ' Copy the source to target 
   If File.Exists(targetFile) Then 
      File.SetAttributes(targetFile, File.GetAttributes(targetFile) And Not FileAttributes.ReadOnly) 
      File.Delete(targetFile) 
   End If 
 
   File.Copy(sourceFile, targetFile, True) 
   File.SetAttributes(targetFile, File.GetAttributes(targetFile) And Not FileAttributes.ReadOnly) 
 
   Dim annotations As New List(Of PDFAnnotation)() 
 
   ' Add a rectangle And a reply to it 
   Const myRectangle As String = "myRectangle" 
   Const myReply As String = "myReply" 
 
   ' Create dashed red pen with width of 2 
   Dim pen As New PDFPen() 
   pen.Color = RasterColor.FromKnownColor(RasterKnownColor.Red) 
   pen.PenStyle = PDFPen.Dashed 
   pen.Width = 2 
 
   ' Create red solid brush 
   Dim brush As New PDFBrush() 
   brush.BrushStyle = PDFBrush.Solid 
   brush.Color = RasterColor.FromKnownColor(RasterKnownColor.Red) 
 
   Dim rectObj As New PDFRectangleAnnotation() 
   rectObj.PageNumber = 1 
   rectObj.Pen = pen 
   rectObj.Brush = brush 
   Dim rect As 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 
   Dim noteObj1 As 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 
   Dim ellipseObj As 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 = Nothing 
   annotations.Add(ellipseObj) 
 
   ' Add an opened note that Is a Not a child of any objects. 
   Dim noteObj2 As 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 = Nothing 
   'noteObj2.ParentObjectNumber = Nothing 
   annotations.Add(noteObj2) 
 
   ' Save the PDF file 
 
   Dim PDFFile As New PDFFile(targetFile) 
   PDFFile.WriteAnnotations(annotations, Nothing) 
 
   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. 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 

Requirements

Target Platforms

Help Version 20.0.2020.4.3
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Pdf Assembly