Search Results for

    Show / Hide Table of Contents

    Class PdfLayer

    One entry from a PDF document's Optional Content Group (OCG / layer) tree. Returned by PdfClient.GetOcgs(documentId) and matched to individual TextObject / PathObject instances via their OcgId property.

    Inheritance
    System.Object
    PdfLayer
    Namespace: IronSoftware
    Assembly: IronPdf.dll
    Syntax
    public class PdfLayer : Object

    Each PdfLayer record represents one entry in a PDF document's Optional Content Group (OCG) tree, the data structure that drives layer visibility in readers such as Adobe Acrobat. Obtaining these records lets a developer enumerate every named layer in a document, check which layers are on or off by default, and correlate individual content objects on the page back to the layer that owns them.

    The PdfClient.GetOcgs(documentId) method returns a collection of PdfLayer objects, one per OCG entry in the document. From there, Id uniquely identifies the layer within the document, and ParentId exposes the parent layer's identifier so nested layer hierarchies can be reconstructed. Name carries the human-readable label shown in a PDF viewer's layers panel. Two boolean properties describe visibility state: DefaultVisible reflects the visibility the document author encoded in the OCG dictionary, while IsVisible reflects the current runtime state, which may differ if the document's open action or a prior API call has toggled layers. ToString() returns a concise diagnostic string combining Id and Name, useful when logging or debugging layer trees.

    To connect layers to page content, compare a layer's Id against the OcgId property on TextObject and PathObject instances retrieved from the same document. This pairing makes it straightforward to extract only the text that belongs to a specific layer, hide all paths on a watermark layer before re-rendering, or audit which content is hidden by default.

    using IronPdf;
    using IronSoftware;
    
    var pdf = PdfDocument.FromFile("layered.pdf");
    IEnumerable<PdfLayer> layers = PdfClient.GetOcgs(pdf.DocumentId);
    
    foreach (PdfLayer layer in layers)
    {
        Console.WriteLine($"{layer.Id} | {layer.Name} | visible={layer.IsVisible} | default={layer.DefaultVisible}");
        if (layer.ParentId >= 0)
            Console.WriteLine($"  child of layer {layer.ParentId}");
    }

    The IronPDF documentation hub covers PDF manipulation in depth. The PDF layers how-to walks through reading and toggling OCG visibility. The extract text from PDF example shows how text content objects are accessed, and the get started guide covers installation and licensing.

    Constructors

    PdfLayer()

    Declaration
    public PdfLayer()

    Properties

    DefaultVisible

    True if the layer is visible under the document's default configuration (/OCProperties/D). Distinct from IsVisible.

    Declaration
    public bool DefaultVisible { get; }
    Property Value
    Type Description
    System.Boolean

    Id

    Stable id matching the array index of this OCG in /OCProperties/OCGs. Use as the join key against TextObject.OcgId and PathObject.OcgId.

    Declaration
    public int Id { get; }
    Property Value
    Type Description
    System.Int32

    IsVisible

    True if a PDF viewer using the default View usage would currently render content tagged with this OCG. False if any visibility expression (defaults, OCMD, intent) hides it.

    Declaration
    public bool IsVisible { get; }
    Property Value
    Type Description
    System.Boolean

    Name

    Display name from the OCG dictionary's /Name entry. May be the empty string for unnamed OCGs.

    Declaration
    public string Name { get; }
    Property Value
    Type Description
    System.String

    ParentId

    Id of the parent OCG when this entry is nested inside another in the /OCProperties/D/Order tree, or -1 if this OCG is at the root.

    Declaration
    public int ParentId { get; }
    Property Value
    Type Description
    System.Int32

    Methods

    ToString()

    Declaration
    public override string ToString()
    Returns
    Type Description
    System.String
    ☀
    ☾
    Downloads
    • Download with Nuget
    • Start for Free
    In This Article
    Back to top
    Install with Nuget