Using walkTree() in C#
📌 Overview
This article demonstrates the use of the walktree()method in C#. This offers the ability to walk through the DOM calling a given function on each node, and can be called on an IDOMFixedPage node to visit every object on a page.
ℹ️ Key Concepts
The function is allowed to:
edit or inspect the node in any way
replace the node (via
parent.replaceNode()orparent->replaceNode()in C++)remove the node (via
parent.extractChild()orparent->extractChild())edit or modify the node's children in any way. However, the result is undefined if the node's siblings are removed or reordered. Keep in mind that if a node within a brush or form is altered, all uses of that brush or form will see the change.
⌨️ Code Example
Two methods for creating the callback are shown below, one with a delegate that provides an additional layer of abstraction. Both point to the same function DumpNodeInfo(); use which ever method suits your needs. Full implementation available at WalkTreeExample.cs.
Method 1 | Method 2 |
|---|---|
C#
C#
|
C#
C#
|
☑️ Conclusion
The walkTree() method in C# provides a powerful way to traverse the DOM, allowing for inspection, modification, and management of nodes within a PDF document. By utilizing the provided code examples and understanding the key concepts, users can effectively manipulate document structures to suit their needs.
📚 Additional Resources
If you need additional help, see our API documentation for detailed information on class/method usage, or raise a support ticket via our customer portal.