Table of Contents

Class PdfLayer

Namespace
iText.Kernel.Pdf.Layer
Assembly
itext.kernel.dll

An optional content group is a dictionary representing a collection of graphics that can be made visible or invisible dynamically by users of viewer applications.

public class PdfLayer : PdfObjectWrapper<PdfDictionary>, IPdfOCG
Inheritance
PdfLayer
Implements
Inherited Members

Remarks

An optional content group is a dictionary representing a collection of graphics that can be made visible or invisible dynamically by users of viewer applications. In iText they are referenced as layers.

To be able to be wrapped with this PdfObjectWrapper<T> the PdfObject must be indirect.

Constructors

PdfLayer(string, PdfDocument)

Creates a new layer by its name and document.

public PdfLayer(string name, PdfDocument document)

Parameters

name string

the layer name

document PdfDocument

the PdfDocument which the layer belongs to

PdfLayer(PdfDictionary)

Creates a new layer by existing dictionary, which must be an indirect object.

public PdfLayer(PdfDictionary layerDictionary)

Parameters

layerDictionary PdfDictionary

the layer dictionary, must have an indirect reference.

Fields

children

protected IList<PdfLayer> children

Field Value

IList<PdfLayer>

locked

protected bool locked

Field Value

bool

on

protected bool on

Field Value

bool

onPanel

protected bool onPanel

Field Value

bool

parent

protected PdfLayer parent

Field Value

PdfLayer

title

Used for titling group of objects but not actually grouping them.

protected string title

Field Value

string

Methods

AddChild(PdfLayer)

Adds a child layer.

public virtual void AddChild(PdfLayer childLayer)

Parameters

childLayer PdfLayer

the child layer

Remarks

Adds a child layer. Nested layers can only have one parent.

AddOCGRadioGroup(PdfDocument, IList<PdfLayer>)

Use this method to set a collection of optional content groups whose states are intended to follow a "radio button" paradigm.

public static void AddOCGRadioGroup(PdfDocument document, IList<PdfLayer> group)

Parameters

document PdfDocument

the PdfDocument

group IList<PdfLayer>

the radio group

Remarks

Use this method to set a collection of optional content groups whose states are intended to follow a "radio button" paradigm. That is, the state of at most one optional content group in the array should be ON at a time: if one group is turned ON, all others must be turned OFF.

CreateTitle(string, PdfDocument)

Creates a title layer.

public static PdfLayer CreateTitle(string title, PdfDocument document)

Parameters

title string

the title text

document PdfDocument

the PdfDocument

Returns

PdfLayer

the title layer

Remarks

Creates a title layer. A title layer is not really a layer but a collection of layers under the same title heading.

CreateTitleSilent(string, PdfDocument)

Creates a title layer without registering it in PdfOCProperties.

protected static PdfLayer CreateTitleSilent(string title, PdfDocument document)

Parameters

title string

the title of the layer

document PdfDocument

the document this title layer belongs to

Returns

PdfLayer

the created layer

GetChildren()

Gets the list of the current child layers of the layer.

public virtual IList<PdfLayer> GetChildren()

Returns

IList<PdfLayer>

the list of the current child layers, null if the layer has no children.

Remarks

Gets the list of the current child layers of the layer. BE CAREFUL! Do not try to add a child layer using the resultant child list, use #addChild method instead.

GetDocument()

Gets the PdfDocument that owns that layer.

protected virtual PdfDocument GetDocument()

Returns

PdfDocument

the PdfDocument that owns that layer

GetIndirectReference()

Gets the indirect reference to the current layer object.

public virtual PdfIndirectReference GetIndirectReference()

Returns

PdfIndirectReference

the indirect reference to the object representing the layer

GetIntents()

Gets a collection of current intents specified for this layer.

public virtual ICollection<PdfName> GetIntents()

Returns

ICollection<PdfName>

the collection of intents.

Remarks

Gets a collection of current intents specified for this layer. The default value is View , so it will be the only element of the resultant collection if no intents are currently specified.

GetParent()

Gets the parent of this layer, be it a title layer, or a usual one.

public virtual PdfLayer GetParent()

Returns

PdfLayer

the parent of the layer, or null if it has no parent

GetTitle()

Gets the title of the layer if it is a title layer, or null if it is a usual layer.

public virtual string GetTitle()

Returns

string

the title of the layer if it is a title layer, or null if it is a usual layer

GetUsage()

Gets the /Usage dictionary, creating a new one if necessary.

protected virtual PdfDictionary GetUsage()

Returns

PdfDictionary

the /Usage dictionary

IsLocked()

Gets whether the layer is currently locked or not.

public virtual bool IsLocked()

Returns

bool

true if the layer is currently locked, false otherwise.

Remarks

Gets whether the layer is currently locked or not. If the layer is locked, it will not be possible to change its state (on/off) in a viewer.

IsOn()

Gets the initial visibility of the layer when the document is opened.

public virtual bool IsOn()

Returns

bool

the initial visibility of the layer

IsOnPanel()

Gets the layer visibility in Acrobat's layer panel

public virtual bool IsOnPanel()

Returns

bool

the layer visibility in Acrobat's layer panel

IsWrappedObjectMustBeIndirect()

protected override bool IsWrappedObjectMustBeIndirect()

Returns

bool

SetCreatorInfo(string, string)

Used by the creating application to store application-specific data associated with this optional content group.

public virtual void SetCreatorInfo(string creator, string subtype)

Parameters

creator string

a text string specifying the application that created the group

subtype string

a string defining the type of content controlled by the group. Suggested values include but are not limited to Artwork, for graphic-design or publishing applications, and Technical, for technical designs such as building plans or schematics

SetExport(bool)

Specifies the recommended state for content in this group when the document (or part of it) is saved by a viewer application to a format that does not support optional content (for example, an earlier version of PDF or a raster image format).

public virtual void SetExport(bool export)

Parameters

export bool

the export state

SetIntents(IList<PdfName>)

Sets the intents of the layer.

public virtual void SetIntents(IList<PdfName> intents)

Parameters

intents IList<PdfName>

the list of intents.

SetLanguage(string, bool)

Specifies the language of the content controlled by this optional content group

public virtual void SetLanguage(string lang, bool preferred)

Parameters

lang string

a language string which specifies a language and possibly a locale (for example, es-MX represents Mexican Spanish)

preferred bool

used by viewer applications when there is a partial match but no exact match between the system language and the language strings in all usage dictionaries

SetLocked(bool)

Use this method to lock an optional content group.

public virtual void SetLocked(bool locked)

Parameters

locked bool

sets whether the layer is currently locked or not

Remarks

Use this method to lock an optional content group. The state of a locked group cannot be changed through the user interface of a viewer application. Producers can use this entry to prevent the visibility of content that depends on these groups from being changed by users.

SetName(string)

Sets the name of the layer to be displayed in the Layers panel.

public virtual void SetName(string name)

Parameters

name string

the name of the layer.

SetOn(bool)

Sets the initial visibility of the layer when the document is opened.

public virtual void SetOn(bool on)

Parameters

on bool

the initial visibility of the layer

SetOnPanel(bool)

Sets the visibility of the layer in Acrobat's layer panel.

public virtual void SetOnPanel(bool onPanel)

Parameters

onPanel bool

the visibility of the layer in Acrobat's layer panel

Remarks

Sets the visibility of the layer in Acrobat's layer panel. If false the layer cannot be directly manipulated by the user. Note that any children layers will also be absent from the panel.

SetPageElement(string)

Indicates that the group contains a pagination artifact.

public virtual void SetPageElement(string pe)

Parameters

pe string

one of the following names: "HF" (Header Footer), "FG" (Foreground), "BG" (Background), or "L" (Logo).

SetPrint(string, bool)

Specifies that the content in this group is intended for use in printing

public virtual void SetPrint(string subtype, bool printState)

Parameters

subtype string

a name specifying the kind of content controlled by the group; for example, Trapping, PrintersMarks and Watermark

printState bool

indicates that the group should be set to that state when the document is printed from a viewer application

SetUser(string, params string[])

Specifies one or more users for whom this optional content group is primarily intended.

public virtual void SetUser(string type, params string[] names)

Parameters

type string

a name that can be Ind (individual), Ttl (title), or Org (organization).

names string[]

one or more text strings representing the name(s) of the individual, position or organization

SetView(bool)

Indicates that the group should be set to that state when the document is opened in a viewer application.

public virtual void SetView(bool view)

Parameters

view bool

the view state

SetZoom(float, float)

Specifies a range of magnifications at which the content in this optional content group is best viewed.

public virtual void SetZoom(float min, float max)

Parameters

min float

the minimum recommended magnification factors at which the group should be ON. A negative value will set the default to 0

max float

the maximum recommended magnification factor at which the group should be ON. A negative value will set the largest possible magnification supported by the viewer application