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
    IronPDF_for_dotnet_log2o
    Blue key in circleGet started for FREE
    No credit card required
    Test in a live environment

    Test in production without watermarks.
    Works wherever you need it to.

    Fully-functional product

    Get 30 days of fully functional product.
    Have it up and running in minutes.

    24/5 technical support

    Full access to our support engineering team during your product trial

    Grey key in circleGet started for FREE
    The trial form was submitted successfully.
    Calendar in circleBook Free Live Demo
    No contact, no card details, no commitments Book a 30-minute, personal demo.
    Here's what to expect:

    A live demo of our product and its key features

    Get project specific feature recommendations

    All your questions are answered to make sure you have all the information you need. (No commitment whatsoever.)

    Grey key in circleBook Free Live Demo
    Your booking has been completed Check your e-mail for confirmation
    Support Team Member 6 related to The C# PDF Library Support Team Member 14 related to The C# PDF Library Support Team Member 4 related to The C# PDF Library Support Team Member 2 related to The C# PDF Library
    Online 24/5
    Need help? Our sales team would be glad to help you.
    Try the Enterprise Trial
    ironpdf_for_dotnet_log2o
    Key in blue circle
    Get your free 30-day Trial Key instantly.
    bullet_checkedNo credit card or account creation required
    Key in blue circle
    Get your free 30-day Trial Key instantly.
    Blue key in circleNo credit card or account creation required
    Green Check in orange circle
    The trial form was submitted successfully.
    badge_greencheck_in_yellowcircle
    Thank you for starting a trial

    Please check your email for the trial license key.

    If you don’t receive an email, please start a live chat or email support@ironsoftware.com

    Install with NuGet
    View Licensing
    • Logo Aetna
    • Logo NASA
    • Logo GE
    • Logo Porsche
    • Logo USDA
    • Logo Qatar
    Join Millions of Engineers who’ve tried IronPDF