Class OptionalContentLayer
- java.lang.Object
-
- org.faceless.pdf2.OptionalContentDescriptor
-
- org.faceless.pdf2.OptionalContentLayer
-
- All Implemented Interfaces:
java.lang.Cloneable
public class OptionalContentLayer extends OptionalContentDescriptor
This class represents an optional content layer in the PDF. Layers can be assigned to a PDFCanvas to allow that layer to be turned on or off in a PDF viewer. Layers can also be set to turn on or off under certain conditions; it's possible to create a layer which is never seen on screen but is printed, for example. Support for this functionality is missing from many PDF viewers.
Here's an example showing how to add a "DRAFT" stamp to a page which is only visible when the PDF is printed or exported to a bitmap.
PDF pdf = new PDF(...); // Read PDF from file // Create the "DRAFT" stamp and draw onto each page PDFCanvas draft = new PDFCanvas(300, 300); PDFStyle style = new PDFStyle(); style.setFont(new StandardFont(StandardFont.HELVETICA), 80); style.setFontStyle(PDFStyle.FONTSTYLE_OUTLINE); draft.setStyle(style); draft.drawGlyphVector(style.createGlyphVector("DRAFT", null), 50, 50); draft.flush(); for (PDFPage page : pdf.getPages()) { page.drawCanvas(draft, 100, 200, 100 + draft.getWidth(), 200 + draft.getHeight()); } // Make "draft" canvas visible when printed only, and lock it. OptionalContentLayer layer = new OptionalContentLayer("Draft"); layer.setDisclosed(false); // Hide from user-interface in Acrobat layer.setEnabled(false); // Turn layer off so it's invisible, but... layer.setPrint(OptionalContentLayer.When.Always); // always print... layer.setExport(OptionalContentLayer.When.Always); // ... and always export draft.setOptionalContentDescriptor(layer); // Critical: add the layer to the canvas pdf.getOptionalContentLayers().add(layer); // Critical: add the layer to the PDF pdf.render(new FileOutputStream("out.pdf"));
- Since:
- 2.23.5
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
OptionalContentLayer.When
The "When" enum can be used to set under what conditions a layer is printed/exported.
-
Constructor Summary
Constructors Constructor Description OptionalContentLayer()
Create a new OptionalContentLayer.OptionalContentLayer(java.lang.String name)
Create a new OptionalContentLayer and set the name
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Object
clone()
java.util.Collection<OptionalContentLayer>
getExclusions()
Return the set of OptionalContentLayers of which at most one should be turned on.OptionalContentLayer.When
getExport()
Return under what conditions the layer is included when the PDF is exported to an image.java.lang.String
getName()
Get the layer name.java.util.List<OptionalContentLayer>
getOptionalContentLayers()
Return ths list of OptionalContentLayers that are children of this layer.OptionalContentLayer.When
getPrint()
Return under what conditions the layer is included when the PDF is printedjava.lang.String
getProcessingStep()
If this optional layer is a Processing Step, as defined by ISO19593, return the processing step as a string.OptionalContentLayer.When
getView()
Return under what conditions the layer is included when the PDF is displayed.boolean
isDisclosed()
Return whether the layer is disclosed in the viewer, as set bysetDisclosed(boolean)
boolean
isEnabled()
Return if this layer is enabled by defaultboolean
isLocked()
Return the "locked" flag as set bysetLocked(boolean)
void
putLiteral(java.lang.String key, java.lang.String tokens)
Put a literal token sequnce.void
setDisclosed(boolean disclosed)
Set whether the layer is disclosed in the viewer user-interface.void
setEnabled(boolean enabled)
Set whether this this layer is enabled by default.void
setExclusions(java.util.Collection<OptionalContentLayer> set)
Set the set of OptionalContentLayers which must be turned off when this layer is turned on.void
setExport(OptionalContentLayer.When when)
Set under what conditions the layer is included when the PDF is exported to an image.void
setLocked(boolean locked)
Set whether the layer is locked in the viewer user-interface.void
setName(java.lang.String name)
Set the layer name.void
setPrint(OptionalContentLayer.When when)
Set under what conditions the layer is included when the PDF is printed.void
setProcessingStep(java.lang.String key)
Set the ISO19593 Processing Step this Optional Content layer represents.void
setView(OptionalContentLayer.When when)
Set under what conditions the layer is included when the PDF is displayed.java.lang.String
toString()
-
Methods inherited from class org.faceless.pdf2.OptionalContentDescriptor
and, not, or
-
-
-
-
Constructor Detail
-
OptionalContentLayer
public OptionalContentLayer()
Create a new OptionalContentLayer. The name is mandatory and must be set an a separate call tosetName(java.lang.String)
-
OptionalContentLayer
public OptionalContentLayer(java.lang.String name)
Create a new OptionalContentLayer and set the name- Parameters:
name
- the name
-
-
Method Detail
-
isEnabled
public boolean isEnabled()
Return if this layer is enabled by default- Overrides:
isEnabled
in classOptionalContentDescriptor
-
setEnabled
public void setEnabled(boolean enabled)
Set whether this this layer is enabled by default. The default is true.- Parameters:
enabled
- the enabled flag
-
getName
public java.lang.String getName()
Get the layer name.- Overrides:
getName
in classOptionalContentDescriptor
-
setName
public void setName(java.lang.String name)
Set the layer name.- Parameters:
name
- , which must not be null
-
isLocked
public boolean isLocked()
Return the "locked" flag as set bysetLocked(boolean)
-
setLocked
public void setLocked(boolean locked)
Set whether the layer is locked in the viewer user-interface. Locked layers cannot have their "enabled" state changed by the user.- Parameters:
locked
- the locked flag
-
isDisclosed
public boolean isDisclosed()
Return whether the layer is disclosed in the viewer, as set bysetDisclosed(boolean)
-
setDisclosed
public void setDisclosed(boolean disclosed)
Set whether the layer is disclosed in the viewer user-interface. Disclosed layers (the default) are listed in the user-interface and can have their properties inspected or possibly changed. Undisclosed layers are not listed in the user-interface.- Parameters:
disclosed
- the disclosed flag
-
getView
public OptionalContentLayer.When getView()
Return under what conditions the layer is included when the PDF is displayed.
-
setView
public void setView(OptionalContentLayer.When when)
Set under what conditions the layer is included when the PDF is displayed. Note that the functionality of this flag is quite unclear; it appears to do the same job asisEnabled()
. We do not recommend setting this flag to anything exceptOptionalContentLayer.When.Enabled
-
getPrint
public OptionalContentLayer.When getPrint()
Return under what conditions the layer is included when the PDF is printed
-
setPrint
public void setPrint(OptionalContentLayer.When when)
Set under what conditions the layer is included when the PDF is printed. The default is "when enabled"
-
getExport
public OptionalContentLayer.When getExport()
Return under what conditions the layer is included when the PDF is exported to an image.
-
setExport
public void setExport(OptionalContentLayer.When when)
Set under what conditions the layer is included when the PDF is exported to an image. The default is "when enabled"
-
getExclusions
public java.util.Collection<OptionalContentLayer> getExclusions()
Return the set of OptionalContentLayers of which at most one should be turned on. This functionality is similar to a "radio button" set. The default is the empty set, meaning there is no radio-button-like functionaity. Otherwise, a set of at least two entries is returned, one of which is this layer. All layers in the returned set should return the same value for this method.
(note that prior to 2.25 this was phrased slightly differently and it was unclear whether "this" was included in the returned set. Now, for any non-empty return value, it's explicit that its always included.)
- Returns:
- either an empty set, or a set of at least two items making up the "radio button group" which includes this layer.
-
setExclusions
public void setExclusions(java.util.Collection<OptionalContentLayer> set)
Set the set of OptionalContentLayers which must be turned off when this layer is turned on. Setting this value to null or an empty set makes this layer independent. Setting it to a set containing other layers will also adjust those other layers so all have the same exclusion set. The supplied set may or may not include this layer; a layer is always a member of its own exclusion group, so its presence is assumed.- Parameters:
set
- the mutually-exclusive set of layers, including this one, to create a "radio-button" set from
-
getOptionalContentLayers
public java.util.List<OptionalContentLayer> getOptionalContentLayers()
Return ths list of OptionalContentLayers that are children of this layer. Nesting layers this way controls the way layers are presented in the user-interface, and nothing else. Invalid content (loops, null objects etc) are cleaned up when the PDF is saved, not before.- Since:
- 2.24.2
-
getProcessingStep
public java.lang.String getProcessingStep()
If this optional layer is a Processing Step, as defined by ISO19593, return the processing step as a string. SeesetProcessingStep(java.lang.String)
for a list of defined values. Otherwise, return null.- Since:
- 2.24.3
-
setProcessingStep
public void setProcessingStep(java.lang.String key)
Set the ISO19593 Processing Step this Optional Content layer represents. The key should be one of the following values:Braille The layer contains contours representing braille that is applied to the printed product after printing Dimensions The layer contains contours giving indications (arrows, numbers and units) of physical sizes of items in the design. Legend The layer contains PDF graphics objects outside the surface of the actual printed product containing job related data used in review and approval and other production steps. White The layer contains PDF graphics objects indicating application of white backing ink, such as might be used on transparent or metallic substrates. Varnish The layer contains PDF graphics objects indicating application of varnish after printing. Structural.Cutting Processing step objects indicating where the printed artwork will be cut from the printed sheet e.g. with a guillotine cutter or die cutting device. Structural.PartialCutting Processing step objects indicating where the substrate will be cut partially i.e. not entirely through the material Structural.ReversePartialCutting Processing step objects indicating where the substrate will be cut partially i.e. not entirely through the material on the back side of the substrate Structural.Creasing Processing step objects indicating where the substrate will be creased to guide subsequent folding. Structural.ReverseCreasing Processing step objects indicating where the substrate will be creased on the back side of the substrate Structural.CuttingCreasing Processing step objects indicating where the substrate will undergo alternating cutting and creasing Structural.ReverseCuttingCreasing Processing step objects indicating where the substrate will undergo alternating cutting and creasing on the back side of the substrate Structural.PartialCuttingCreasing Processing step objects indicating where the substrate will undergo alternating partial cutting and creasing Structural.ReversePartialCuttingCreasing Processing step objects indicating where the substrate will undergo alternating partial cutting and creasing on the back side of the substrate Structural.Drilling Processing step objects indicating locations where the substrate will be drilled and the intended size of the resulting hole. Structural.Gluing Processing step objects enclosing an area where glue will be applied. Structural.FoilStamping Processing step objects enclosing an area where foil will be applied through hot foil stamping. Structural.ColdFoilStamping Processing step objects enclosing an area where foil will be applied through cold foil stamping (i.e. using glue) Structural.Embossing Processing step objects enclosing an area where embossing will be applied. Structural.Debossing Processing step objects enclosing an area where debossing will be applied. Structural.Perforating Processing step objects indicating where the substrate will be perforated. Structural.Bleed Processing step objects indicating the intended bleed for print. Structural.VarnishFree Processing step objects enclosing an area where it is not allowed to have varnish. Structural.InkFree Processing step objects enclosing an area where it is not allowed to have printing ink. Structural.InkVarnishFree Processing step objects enclosing an area where it is not allowed to have printing ink and where it is not allowed to have varnish. Structural.Folding Processing step objects indicating where the substrate will be folded without prior creasing. Structural.Punching Processing steps objects indicating the locations at which the substrate will be punched and the size and shape of the resulting holes. Structural.Stapling Processing steps objects indicating the locations at which the substrate will be stapled or stitched, and the size of the staples or stitches to be used. Positions.Hologram Processing step objects that indicate the intended position of holograms. Positions.Barcode Processing step objects that indicate the intended position of barcodes Positions.ContentArea Processing step objects that indicate areas where it is allowed to place text and other graphical elements. Positions.CodingMarking Processing step objects specific to packaging that indicate areas where additional information not contained in the PDF will be printed on the packaging at a post-press stage, such as on filling lines where final products are being packed. Some examples of information that might be marked as CodingMarking include but are not limited to best before dates, lot numbers, production dates, and tracking codes. Positions.Imprinting Processing step objects that indicate areas where additional information (e.g. variable data) will be printed on pre-printed shells which contain the bulk of the graphical content, as a secondary print stage prior to finishing. null
will remove any special significance from this layer- Since:
- 2.24.3
-
toString
public java.lang.String toString()
- Overrides:
toString
in classOptionalContentDescriptor
-
putLiteral
public void putLiteral(java.lang.String key, java.lang.String tokens)
Put a literal token sequnce. For debugging- Parameters:
key
- the keytokens
- the token sequence, eg "true" or "/foo" or "[/Foo/Bar]". No refs, just direct objects.
-
clone
protected java.lang.Object clone()
- Overrides:
clone
in classjava.lang.Object
-
-