๐Ÿ“ Optional Content Layers

Show/hide content groups for blueprints, maps, annotations, and versioned content.

C# โ€” OCG Layers
// Create named layers
var base_ = doc.CreateOptionalContentGroup(
    "Base Drawing", visible: true);
var dims = doc.CreateOptionalContentGroup(
    "Dimensions", visible: true);
var notes = doc.CreateOptionalContentGroup(
    "Notes", visible: false);

// Base layer content
page.BeginOptionalContent(base_);
page.FillRectangle(100, 400, 200, 150,
    new PdfDrawOptions {
        FillColor = new PdfColor(0.9, 0.9, 0.95)
    });
page.EndOptionalContent();

// Dimensions overlay
page.BeginOptionalContent(dims);
page.AddText("200 pt", 160, 560,
    new PdfTextOptions {
        FontSize = 9,
        Color = new PdfColor(0.8, 0, 0)
    });
page.EndOptionalContent();

// Hidden notes layer
page.BeginOptionalContent(notes);
page.AddText("NOTE: dimensions in points",
    100, 380);
page.EndOptionalContent();
Screenshot of the Layers PDF in a viewer with the Layers panel open showing three toggleable layers: Base Drawing (checked), Dimensions (checked), and Notes (unchecked) โ€” the main content area shows a floor plan rectangle with red dimension lines overlaid

You should see a bold "Optional Content Layers" heading, an instruction paragraph, a light grey floor-plan rectangle labelled "Floor Plan", and red dashed dimension lines showing 200 pt and 150 pt. Open the Layers panel in your viewer: "Base Drawing" and "Dimensions" are on by default; "Notes" is hidden. Toggle them to show or hide each layer.
File: 14_layers.pdf

โ™ฟ Accessibility Tip

Associate OCG content with the structure tree using structureElement.OptionalContentGroup = ocg so assistive technology can present the layer relationship to users.