Package com.itextpdf.kernel.pdf
Class PdfResources
- java.lang.Object
-
- com.itextpdf.kernel.pdf.PdfObjectWrapper<PdfDictionary>
-
- com.itextpdf.kernel.pdf.PdfResources
-
public class PdfResources extends PdfObjectWrapper<PdfDictionary>
Wrapper class that represent resource dictionary - that define named resources used by content streams operators. (ISO 32000-1, 7.8.3 Resource Dictionaries)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
PdfResources.ResourceNameGenerator
Represents a resource name generator.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
Cs
private PdfResources.ResourceNameGenerator
csNamesGen
private PdfResources.ResourceNameGenerator
egsNamesGen
private static java.lang.String
F
private static java.lang.String
Fm
private PdfResources.ResourceNameGenerator
fontNamesGen
private PdfResources.ResourceNameGenerator
formNamesGen
private static java.lang.String
Gs
private static java.lang.String
Im
private PdfResources.ResourceNameGenerator
imageNamesGen
private boolean
isModified
private static java.lang.String
P
private PdfResources.ResourceNameGenerator
patternNamesGen
private static java.lang.String
Pr
private PdfResources.ResourceNameGenerator
propNamesGen
private boolean
readOnly
private java.util.Map<PdfObject,PdfName>
resourceToName
private static java.lang.String
Sh
private PdfResources.ResourceNameGenerator
shadingNamesGen
-
Constructor Summary
Constructors Constructor Description PdfResources()
Creates new instance from empty dictionary.PdfResources(PdfDictionary pdfObject)
Creates new instance from given dictionary.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PdfName
addColorSpace(PdfColorSpace cs)
AddsPdfColorSpace
object to the resources.PdfName
addColorSpace(PdfObject colorSpace)
AddsPdfObject
to the resources as color space.PdfName
addExtGState(PdfExtGState extGState)
AddsPdfExtGState
object to the resources.PdfName
addExtGState(PdfDictionary extGState)
AddsPdfDictionary
to the resources as graphics state parameter dictionary.PdfName
addFont(PdfDocument pdfDocument, PdfFont font)
Adds font to resources and registers PdfFont in the document for further flushing.PdfName
addForm(PdfStream form)
AddsPdfStream
to the resources as form.PdfName
addForm(PdfFormXObject form)
AddsPdfFormXObject
object to the resources.PdfName
addForm(PdfFormXObject form, PdfName name)
Adds the given Form XObject to the current instance ofPdfResources
.PdfName
addImage(PdfStream image)
AddsPdfStream
to the resources as image.PdfName
addImage(PdfImageXObject image)
AddsPdfImageXObject
object to the resources.PdfName
addPattern(PdfPattern pattern)
AddsPdfPattern
object to the resources.PdfName
addPattern(PdfDictionary pattern)
AddsPdfDictionary
to the resources as pattern.PdfName
addProperties(PdfDictionary properties)
AddsPdfDictionary
to the resources as properties list.protected void
addResource(PdfObject resource, PdfName resType, PdfName resName)
(package private) PdfName
addResource(PdfObject resource, PdfResources.ResourceNameGenerator nameGen)
(package private) <T extends PdfObject>
PdfNameaddResource(PdfObjectWrapper<T> resource, PdfResources.ResourceNameGenerator nameGen)
PdfName
addShading(AbstractPdfShading shading)
AddsAbstractPdfShading
object to the resources.PdfName
addShading(PdfDictionary shading)
AddsPdfDictionary
to the resources as shading dictionary.protected void
buildResources(PdfDictionary dictionary)
private void
checkAndResolveCircularReferences(PdfObject pdfObject)
PdfColorSpace
getColorSpace(PdfName name)
PdfFormXObject
getForm(PdfName name)
PdfImageXObject
getImage(PdfName name)
PdfPattern
getPattern(PdfName name)
PdfExtGState
getPdfExtGState(PdfName name)
PdfArray
getProcSet()
Gets the array of predefined procedure set names (see ISO-320001 Paragraph 14.2).PdfObject
getProperties(PdfName name)
PdfDictionary
getResource(PdfName resType)
Get thePdfDictionary
object that that contain resources of specified type.PdfName
getResourceName(PdfObject resource)
Gets the mapped resource name of the givenPdfObject
.<T extends PdfObject>
PdfNamegetResourceName(PdfObjectWrapper<T> resource)
Gets the mapped resource name of thePdfObject
under the given wrapper.java.util.Set<PdfName>
getResourceNames()
Gets the names of all the added resources.java.util.Set<PdfName>
getResourceNames(PdfName resType)
Gets the names of all resources of specified type.PdfObject
getResourceObject(PdfName resType, PdfName resName)
Get thePdfObject
object with specified type and name.AbstractPdfShading
getShading(PdfName name)
protected boolean
isModified()
protected boolean
isReadOnly()
protected boolean
isWrappedObjectMustBeIndirect()
Defines if the object behind this wrapper must be an indirect object in the resultant document.void
setDefaultCmyk(PdfColorSpace defaultCs)
Sets the value of default CMYK Color Space (see ISO-320001 Paragraph 8.6.5.6).void
setDefaultGray(PdfColorSpace defaultCs)
Sets the value of default Gray Color Space (see ISO-320001 Paragraph 8.6.5.6).void
setDefaultRgb(PdfColorSpace defaultCs)
Sets the value of default RGB Color Space (see ISO-320001 Paragraph 8.6.5.6).PdfObjectWrapper<PdfDictionary>
setModified()
void
setProcSet(PdfArray array)
Sets the array of predefined procedure set names (see ISO-320001 Paragraph 14.2).protected void
setReadOnly(boolean readOnly)
-
Methods inherited from class com.itextpdf.kernel.pdf.PdfObjectWrapper
ensureObjectIsAddedToDocument, ensureUnderlyingObjectHasIndirectReference, flush, getPdfObject, isFlushed, makeIndirect, makeIndirect, markObjectAsIndirect, setForbidRelease, setPdfObject, unsetForbidRelease
-
-
-
-
Field Detail
-
F
private static final java.lang.String F
- See Also:
- Constant Field Values
-
Im
private static final java.lang.String Im
- See Also:
- Constant Field Values
-
Fm
private static final java.lang.String Fm
- See Also:
- Constant Field Values
-
Gs
private static final java.lang.String Gs
- See Also:
- Constant Field Values
-
Pr
private static final java.lang.String Pr
- See Also:
- Constant Field Values
-
Cs
private static final java.lang.String Cs
- See Also:
- Constant Field Values
-
P
private static final java.lang.String P
- See Also:
- Constant Field Values
-
Sh
private static final java.lang.String Sh
- See Also:
- Constant Field Values
-
fontNamesGen
private PdfResources.ResourceNameGenerator fontNamesGen
-
imageNamesGen
private PdfResources.ResourceNameGenerator imageNamesGen
-
formNamesGen
private PdfResources.ResourceNameGenerator formNamesGen
-
egsNamesGen
private PdfResources.ResourceNameGenerator egsNamesGen
-
propNamesGen
private PdfResources.ResourceNameGenerator propNamesGen
-
csNamesGen
private PdfResources.ResourceNameGenerator csNamesGen
-
patternNamesGen
private PdfResources.ResourceNameGenerator patternNamesGen
-
shadingNamesGen
private PdfResources.ResourceNameGenerator shadingNamesGen
-
readOnly
private boolean readOnly
-
isModified
private boolean isModified
-
-
Constructor Detail
-
PdfResources
public PdfResources(PdfDictionary pdfObject)
Creates new instance from given dictionary.- Parameters:
pdfObject
- thePdfDictionary
object from which the resource object will be created.
-
PdfResources
public PdfResources()
Creates new instance from empty dictionary.
-
-
Method Detail
-
addFont
public PdfName addFont(PdfDocument pdfDocument, PdfFont font)
Adds font to resources and registers PdfFont in the document for further flushing.- Parameters:
pdfDocument
- aPdfDocument
instance to which the font is added for further flushingfont
- aPdfFont
instance to be added- Returns:
- added font resource name.
-
addImage
public PdfName addImage(PdfImageXObject image)
AddsPdfImageXObject
object to the resources.- Parameters:
image
- thePdfImageXObject
to add.- Returns:
- added image resource name.
-
addImage
public PdfName addImage(PdfStream image)
AddsPdfStream
to the resources as image.- Parameters:
image
- thePdfStream
to add.- Returns:
- added image resources name.
-
getImage
public PdfImageXObject getImage(PdfName name)
-
addForm
public PdfName addForm(PdfFormXObject form)
AddsPdfFormXObject
object to the resources.- Parameters:
form
- thePdfFormXObject
to add.- Returns:
- added form resource name.
-
addForm
public PdfName addForm(PdfStream form)
AddsPdfStream
to the resources as form.- Parameters:
form
- thePdfStream
to add.- Returns:
- added form resources name.
-
addForm
public PdfName addForm(PdfFormXObject form, PdfName name)
Adds the given Form XObject to the current instance ofPdfResources
.- Parameters:
form
- Form XObject.name
- Preferred name for the given Form XObject.- Returns:
- the
PdfName
of the newly added resource
-
getForm
public PdfFormXObject getForm(PdfName name)
-
addExtGState
public PdfName addExtGState(PdfExtGState extGState)
AddsPdfExtGState
object to the resources.- Parameters:
extGState
- thePdfExtGState
to add.- Returns:
- added graphics state parameter dictionary resource name.
-
addExtGState
public PdfName addExtGState(PdfDictionary extGState)
AddsPdfDictionary
to the resources as graphics state parameter dictionary.- Parameters:
extGState
- thePdfDictionary
to add.- Returns:
- added graphics state parameter dictionary resources name.
-
getPdfExtGState
public PdfExtGState getPdfExtGState(PdfName name)
-
addProperties
public PdfName addProperties(PdfDictionary properties)
AddsPdfDictionary
to the resources as properties list.- Parameters:
properties
- thePdfDictionary
to add.- Returns:
- added properties list resources name.
-
addColorSpace
public PdfName addColorSpace(PdfColorSpace cs)
AddsPdfColorSpace
object to the resources.- Parameters:
cs
- thePdfColorSpace
to add.- Returns:
- added color space resource name.
-
addColorSpace
public PdfName addColorSpace(PdfObject colorSpace)
AddsPdfObject
to the resources as color space.- Parameters:
colorSpace
- thePdfObject
to add.- Returns:
- added color space resources name.
-
getColorSpace
public PdfColorSpace getColorSpace(PdfName name)
-
addPattern
public PdfName addPattern(PdfPattern pattern)
AddsPdfPattern
object to the resources.- Parameters:
pattern
- thePdfPattern
to add.- Returns:
- added pattern resource name.
-
addPattern
public PdfName addPattern(PdfDictionary pattern)
AddsPdfDictionary
to the resources as pattern.- Parameters:
pattern
- thePdfDictionary
to add.- Returns:
- added pattern resources name.
-
getPattern
public PdfPattern getPattern(PdfName name)
-
addShading
public PdfName addShading(AbstractPdfShading shading)
AddsAbstractPdfShading
object to the resources.- Parameters:
shading
- theAbstractPdfShading
to add.- Returns:
- added shading resource name.
-
addShading
public PdfName addShading(PdfDictionary shading)
AddsPdfDictionary
to the resources as shading dictionary.- Parameters:
shading
- thePdfDictionary
to add.- Returns:
- added shading dictionary resources name.
-
getShading
public AbstractPdfShading getShading(PdfName name)
-
isReadOnly
protected boolean isReadOnly()
-
setReadOnly
protected void setReadOnly(boolean readOnly)
-
isModified
protected boolean isModified()
-
setModified
public PdfObjectWrapper<PdfDictionary> setModified()
- Overrides:
setModified
in classPdfObjectWrapper<PdfDictionary>
-
setDefaultGray
public void setDefaultGray(PdfColorSpace defaultCs)
Sets the value of default Gray Color Space (see ISO-320001 Paragraph 8.6.5.6).- Parameters:
defaultCs
- the color space to set.
-
setDefaultRgb
public void setDefaultRgb(PdfColorSpace defaultCs)
Sets the value of default RGB Color Space (see ISO-320001 Paragraph 8.6.5.6).- Parameters:
defaultCs
- the color space to set.
-
setDefaultCmyk
public void setDefaultCmyk(PdfColorSpace defaultCs)
Sets the value of default CMYK Color Space (see ISO-320001 Paragraph 8.6.5.6).- Parameters:
defaultCs
- the color space to set.
-
getResourceName
public <T extends PdfObject> PdfName getResourceName(PdfObjectWrapper<T> resource)
Gets the mapped resource name of thePdfObject
under the given wrapper.
Note: if the name for the object won't be found, then the name of object's Indirect Reference will be searched.
-
getResourceName
public PdfName getResourceName(PdfObject resource)
Gets the mapped resource name of the givenPdfObject
.
Note: if the name for the object won't be found, then the name of object's Indirect Reference will be searched.- Parameters:
resource
- the object, for which the name will be searched.- Returns:
- the mapped resource name or
null
if object isn't added to resources.
-
getResourceNames
public java.util.Set<PdfName> getResourceNames()
Gets the names of all the added resources.- Returns:
- the name of all the added resources.
-
getProcSet
public PdfArray getProcSet()
Gets the array of predefined procedure set names (see ISO-320001 Paragraph 14.2). Deprecated in PDF 2.0.- Returns:
- the array of predefined procedure set names.
-
setProcSet
public void setProcSet(PdfArray array)
Sets the array of predefined procedure set names (see ISO-320001 Paragraph 14.2). Deprecated in PDF 2.0.- Parameters:
array
- the array of predefined procedure set names to be set.
-
getResourceNames
public java.util.Set<PdfName> getResourceNames(PdfName resType)
Gets the names of all resources of specified type.- Parameters:
resType
- the resource type. Should bePdfName.ColorSpace
,PdfName.ExtGState
,PdfName.Pattern
,PdfName.Shading
,PdfName.XObject
,PdfName.Font
.- Returns:
- set of resources name of corresponding type. May be empty. Will be empty in case of incorrect resource type.
-
getResource
public PdfDictionary getResource(PdfName resType)
Get thePdfDictionary
object that that contain resources of specified type.- Parameters:
resType
- the resource type. Should bePdfName.ColorSpace
,PdfName.ExtGState
,PdfName.Pattern
,PdfName.Shading
,PdfName.XObject
,PdfName.Font
.- Returns:
- the
PdfDictionary
object containing all resources of specified type, ornull
in case of incorrect resource type.
-
getResourceObject
public PdfObject getResourceObject(PdfName resType, PdfName resName)
Get thePdfObject
object with specified type and name.- Parameters:
resType
- the resource type. Should bePdfName.ColorSpace
,PdfName.ExtGState
,PdfName.Pattern
,PdfName.Shading
,PdfName.XObject
,PdfName.Font
.resName
- the name of the resource object.- Returns:
- the
PdfObject
with specified name in the resources of specified type ornull
in case of incorrect type or missing resource with such name.
-
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.
-
addResource
<T extends PdfObject> PdfName addResource(PdfObjectWrapper<T> resource, PdfResources.ResourceNameGenerator nameGen)
-
addResource
PdfName addResource(PdfObject resource, PdfResources.ResourceNameGenerator nameGen)
-
buildResources
protected void buildResources(PdfDictionary dictionary)
-
checkAndResolveCircularReferences
private void checkAndResolveCircularReferences(PdfObject pdfObject)
-
-