How do I programmatically group annotations?

38 views
Skip to first unread message

Shakthi Wijeratne

unread,
Mar 9, 2021, 2:40:46 PM3/9/21
to PDFTron SDK

Q: 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?

A: 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
grouped.pdf
Reply all
Reply to author
Forward
0 new messages