Package com.itextpdf.kernel.pdf.layer
Class PdfLayer
- All Implemented Interfaces:
-
IPdfOCG
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
To be able to be wrapped with this
PdfObjectWrapper
the PdfObject
must be indirect.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionPdfLayer
(PdfDictionary layerDictionary) Creates a new layer by existing dictionary, which must be an indirect object.PdfLayer
(String name, PdfDocument document) Creates a new layer by its name and document. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a child layer.static void
addOCGRadioGroup
(PdfDocument document, List<PdfLayer> group) Use this method to set a collection of optional content groups whose states are intended to follow a "radio button" paradigm.static PdfLayer
createTitle
(String title, PdfDocument document) Creates a title layer.protected static PdfLayer
createTitleSilent
(String title, PdfDocument document) Creates a title layer without registering it in PdfOCProperties.Gets the list of the current child layers of the layer.protected PdfDocument
Gets thePdfDocument
that owns that layer.Gets the indirect reference to the current layer object.Gets a collection of current intents specified for this layer.Gets the parent of this layer, be it a title layer, or a usual one.getTitle()
Gets the title of the layer if it is a title layer, or null if it is a usual layer.protected PdfDictionary
getUsage()
Gets the /Usage dictionary, creating a new one if necessary.boolean
isLocked()
Gets whether the layer is currently locked or not.boolean
isOn()
Gets the initial visibility of the layer when the document is opened.boolean
Gets the layer visibility in Acrobat's layer panelprotected boolean
Defines if the object behind this wrapper must be an indirect object in the resultant document.void
setCreatorInfo
(String creator, String subtype) Used by the creating application to store application-specific data associated with this optional content group.void
setExport
(boolean export) 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).void
setIntents
(List<PdfName> intents) Sets the intents of the layer.void
setLanguage
(String lang, boolean preferred) Specifies the language of the content controlled by this optional content groupvoid
setLocked
(boolean locked) Use this method to lock an optional content group.void
Sets the name of the layer to be displayed in the Layers panel.void
setOn
(boolean on) Sets the initial visibility of the layer when the document is opened.void
setOnPanel
(boolean onPanel) Sets the visibility of the layer in Acrobat's layer panel.void
setPageElement
(String pe) Indicates that the group contains a pagination artifact.void
Specifies that the content in this group is intended for use in printingvoid
Specifies one or more users for whom this optional content group is primarily intended.void
setView
(boolean view) Indicates that the group should be set to that state when the document is opened in a viewer application.void
setZoom
(float min, float max) Specifies a range of magnifications at which the content in this optional content group is best viewed.Methods inherited from class com.itextpdf.kernel.pdf.PdfObjectWrapper
ensureObjectIsAddedToDocument, ensureUnderlyingObjectHasIndirectReference, flush, getPdfObject, isFlushed, makeIndirect, makeIndirect, markObjectAsIndirect, setForbidRelease, setModified, setPdfObject, unsetForbidRelease
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.itextpdf.kernel.pdf.layer.IPdfOCG
getPdfObject
-
Field Details
-
title
Used for titling group of objects but not actually grouping them. -
on
protected boolean on -
onPanel
protected boolean onPanel -
locked
protected boolean locked -
parent
-
children
-
-
Constructor Details
-
PdfLayer
Creates a new layer by existing dictionary, which must be an indirect object.- Parameters:
-
layerDictionary
- the layer dictionary, must have an indirect reference.
-
PdfLayer
Creates a new layer by its name and document.- Parameters:
-
name
- the layer name -
document
- the PdfDocument which the layer belongs to
-
-
Method Details
-
createTitle
Creates a title layer. A title layer is not really a layer but a collection of layers under the same title heading.- Parameters:
-
title
- the title text -
document
- thePdfDocument
- Returns:
- the title layer
-
addOCGRadioGroup
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.- Parameters:
-
document
- thePdfDocument
-
group
- the radio group
-
addChild
Adds a child layer. Nested layers can only have one parent.- Parameters:
-
childLayer
- the child layer
-
getParent
Gets the parent of this layer, be it a title layer, or a usual one.- Returns:
- the parent of the layer, or null if it has no parent
-
setName
Sets the name of the layer to be displayed in the Layers panel.- Parameters:
-
name
- the name of the layer.
-
isOn
public boolean isOn()Gets the initial visibility of the layer when the document is opened.- Returns:
- the initial visibility of the layer
-
setOn
public void setOn(boolean on) Sets the initial visibility of the layer when the document is opened.- Parameters:
-
on
- the initial visibility of the layer
-
isLocked
public boolean isLocked()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.- Returns:
- true if the layer is currently locked, false otherwise.
-
setLocked
public void setLocked(boolean locked) 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.- Parameters:
-
locked
- sets whether the layer is currently locked or not
-
isOnPanel
public boolean isOnPanel()Gets the layer visibility in Acrobat's layer panel- Returns:
- the layer visibility in Acrobat's layer panel
-
setOnPanel
public void setOnPanel(boolean onPanel) Sets the visibility of the layer in Acrobat's layer panel. Iffalse
the layer cannot be directly manipulated by the user. Note that any children layers will also be absent from the panel.- Parameters:
-
onPanel
- the visibility of the layer in Acrobat's layer panel
-
getIntents
Gets a collection of current intents specified for this layer. The default value isPdfName.View
, so it will be the only element of the resultant collection if no intents are currently specified.- Returns:
- the collection of intents.
-
setIntents
Sets the intents of the layer.- Parameters:
-
intents
- the list of intents.
-
setCreatorInfo
Used by the creating application to store application-specific data associated with this optional content group.- Parameters:
-
creator
- a text string specifying the application that created the group -
subtype
- 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
-
setLanguage
Specifies the language of the content controlled by this optional content group- Parameters:
-
lang
- a language string which specifies a language and possibly a locale (for example, es-MX represents Mexican Spanish) -
preferred
- 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
-
setExport
public void setExport(boolean export) 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).- Parameters:
-
export
- the export state
-
setZoom
public void setZoom(float min, float max) Specifies a range of magnifications at which the content in this optional content group is best viewed.- Parameters:
-
min
- the minimum recommended magnification factors at which the group should be ON. A negative value will set the default to 0 -
max
- 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
-
setPrint
Specifies that the content in this group is intended for use in printing- Parameters:
-
subtype
- a name specifying the kind of content controlled by the group; for example, Trapping, PrintersMarks and Watermark -
printState
- indicates that the group should be set to that state when the document is printed from a viewer application
-
setView
public void setView(boolean view) Indicates that the group should be set to that state when the document is opened in a viewer application.- Parameters:
-
view
- the view state
-
setUser
Specifies one or more users for whom this optional content group is primarily intended.- Parameters:
-
type
- a name that can be Ind (individual), Ttl (title), or Org (organization). -
names
- one or more text strings representing the name(s) of the individual, position or organization
-
setPageElement
Indicates that the group contains a pagination artifact.- Parameters:
-
pe
- one of the following names: "HF" (Header Footer), "FG" (Foreground), "BG" (Background), or "L" (Logo).
-
getIndirectReference
Gets the indirect reference to the current layer object.- Specified by:
-
getIndirectReference
in interfaceIPdfOCG
- Returns:
- the indirect reference to the object representing the layer
-
getTitle
Gets the title of the layer if it is a title layer, or null if it is a usual layer.- Returns:
- the title of the layer if it is a title layer, or null if it is a usual layer
-
getChildren
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.- Returns:
- the list of the current child layers, null if the layer has no children.
-
isWrappedObjectMustBeIndirect
protected boolean isWrappedObjectMustBeIndirect()Description copied from class:PdfObjectWrapper
Defines if the object behind this wrapper must be an indirect object in the resultant document.
If this method returns true it doesn't necessarily mean that object must be in the indirect state at any moment, but rather defines that when the object will be written to the document it will be transformed into indirect object if it's not indirect yet.
Return value of this method shouldn't depend on any logic, it should return always true or false.- Specified by:
-
isWrappedObjectMustBeIndirect
in classPdfObjectWrapper<PdfDictionary>
- Returns:
- true if in the resultant document the object behind the wrapper must be indirect, otherwise false.
-
getDocument
Gets thePdfDocument
that owns that layer.- Returns:
-
the
PdfDocument
that owns that layer
-
createTitleSilent
Creates a title layer without registering it in PdfOCProperties.- Parameters:
-
title
- the title of the layer -
document
- the document this title layer belongs to - Returns:
- the created layer
-
getUsage
Gets the /Usage dictionary, creating a new one if necessary.- Returns:
- the /Usage dictionary
-