Optional relationship between this annotation object and its parent.
public string Relationship { get; set; }
Optional relationship between this annotation object and its parent. The default value is null.
To set a relationship between an object and its parent, set this value to one of Relationship to one of the `Relation' constants defined in PDFAnnotation, such as RelationGroup or RelationReply.
Refer to ObjectNumber for more information and an example.
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:\LEADTOOLS23\Resources\Images";
}