Creating and keeping track of unique element on a page

Q: How do I create an keep track of a specific element on a page?
For example, let’s say I want to create a path that I later might want to edit as a response to other changes.

You can, however, create it as a Form XObject, give it a unique key and then reference this from the path you created.

Created the Form XObject is very similar to creating a regular object, it’s just that you create it on the doc as opposed to the page.

Obj CreateMyFormXObject(string key, string val)
ElementWriter writer = new ElementWriter();
ElementBuilder eb = new ElementBuilder();

eb.MoveTo(0, 0);
eb.CurveTo(500, 500, 125, 625, 0, 500);
eb.CurveTo(-125, 625, -500, 500, 0, 0);
Element heart = eb.PathEnd();
heart.GetGState().SetFillColor(new ColorPt(1, 0, 0));
Obj form_xobj_dict = writer.End();

form_xobj_dict.Put(“Subtype”, Obj.CreateName(“Form”)); // Set bounding box/clipping rectangle.
form_xobj_dict.Put(“BBox”, Rect.CreateSDFRect(0, 0, 400, 600));

// Add a custom key and value:
form_xobj_dict.PutString(key, val);
return form_xobj_dict;

More info about creating and processing Form XObjects!searchin/pdfnet-sdk/create$20form$20xobject/pdfnet-sdk/0N2oEZJyPNA/XYPFSuPqVbwJ!searchin/pdfnet-sdk/create$20form$20xobject/pdfnet-sdk/vaYdPU3hHOE/XYDZnQ6NP_sJ

More info about custom entries:!searchin/pdfnet-sdk/custom$20object/pdfnet-sdk/06RcZalQI0s/sS6Ge3YiZiMJ

ElementWriter pageWriter = new ElementWriter();
ElementBuilder pageBuilder = new ElementBuilder();
Obj form_xobj_dict = CreateMyFormXObject(“MyUniqueKey”, “MyUniqueObject1”);
Element element = pageBuilder.CreateForm(form_xobj_dict);

Later, when we want to edit this path, we can edit this Form XObject instead. To edit the page where this is displayed, check the ElementEdit sample:
While looping through the elements, if the element is of type e_form, you can call element.GetXObject to get an pdftron.SDF.Obj object. To check if it’s the object you created, you can use the following code:
DictIterator ditr = obj.Get(“MyUniqueKey”);
Obj val = ditr.Value();
string str = val.GetAsPDFText();

// If str is “MyUniqueObject1” then you can edit obj using standard methods.