How do I programmatically group annotations?

I have two or more annotations that I would like to group, so that they can be selected and moved as a single item. How can I do this programmatically?

Grouping can be programmatically done by first selecting a “parent” annotation and adding a reference to it on the other “children” annotations.

For an example, please see the following documents and code, where the stickynote annotation is the parent and the other two are its children:

PDFDoc doc = new PDFDoc(@"blank.pdf")
Page pg = doc.GetPage(1);
Annot parent = pg.GetAnnot(0); // parent

Annot child1 = pg.GetAnnot(2); // first child
child1.GetSDFObj().PutName("RT", "Group");
child1.GetSDFObj().Put("IRT", parent.GetSDFObj());

Annot child2 = pg.GetAnnot(3); // second child
child2.GetSDFObj().PutName("RT", "Group");
child2.GetSDFObj().Put("IRT", parent.GetSDFObj());

doc.Save(@"grouped.pdf", SDFDoc.SaveOptions.e_linearized);

blank.pdf (9.59 KB)

grouped.pdf (10.5 KB)

1 Like