Skip to main content
Skip table of contents

Working with paths

Overview

Paths in documents can be accessed by finding the path nodes on a page. Each path node will have the following structure:

  • Path Node (IDOMPathNode)
    • Geometry (IDOMPathGeometry)
      • Figures (IDOMPathFigure)
        • Segments (IDOMPathSegment)

Finding paths

The following code finds all path nodes font anywhere within the content node.

C#
CEDLVectIDOMNode pathNodes = content.findChildrenOfType(eDOMNodeType.eDOMPathNode);

Finding a path using a specific spot color

Sometimes it may be useful to find a path, which has a fill or stroke using a specific spot color. This can be useful when dealing with PDFs that contain technical marks, such as cut contours.

In this case, the following code can help:

C#
public static IDOMPathNode FindPathWithColorant(IDOMFixedPage pageContent, string colorantName)
{
    using var paths = pageContent.findChildrenOfType(eDOMNodeType.eDOMPathNode);
    foreach (var path in paths.toVector())
    {
        var pathNode = IDOMPathNode.fromRCObject(path.toRCObject());

        using var stroke = pathNode.getStroke();
        if (stroke == null || stroke.getBrushType() != IDOMBrush.eBrushType.eSolidColor)
            continue;

        using var solidBrush = IDOMSolidColorBrush.fromRCObject(stroke.toRCObject());
        using var color = solidBrush.getColor();
        using var colorSpace = color.getColorSpace();

        if (colorSpace.getColorSpaceType() != IDOMColorSpace.eColorSpaceType.eDeviceN)
            continue;

        using var deviceNColorSpace = IDOMColorSpaceDeviceN.fromRCObject(colorSpace.toRCObject());
        for (byte deviceNIndex = 0; deviceNIndex < deviceNColorSpace.getNumComponents(); deviceNIndex++)
        {
            using var component = deviceNColorSpace.getColorant(deviceNIndex);
            if (component.getName() == colorantName)
                return pathNode;
        }
    }

    return null;
}

In this code, we enumerate all the paths in the document. For each path, we get its fill brush and see if it uses a DeviceN colorspace. If it does, we enumerate through its components and check if any of the colorant names matches our spot color name.

In this simple example, we then return the first match. 

This code could be adapted to remove or transform paths which use a specific spot color, with IDOMNode.extractChild() which removes a node from a tree.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.