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 classPdfResources.ResourceNameGeneratorRepresents a resource name generator.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringCsprivate PdfResources.ResourceNameGeneratorcsNamesGenprivate PdfResources.ResourceNameGeneratoregsNamesGenprivate static java.lang.StringFprivate static java.lang.StringFmprivate PdfResources.ResourceNameGeneratorfontNamesGenprivate PdfResources.ResourceNameGeneratorformNamesGenprivate static java.lang.StringGsprivate static java.lang.StringImprivate PdfResources.ResourceNameGeneratorimageNamesGenprivate booleanisModifiedprivate static java.lang.StringPprivate PdfResources.ResourceNameGeneratorpatternNamesGenprivate static java.lang.StringPrprivate PdfResources.ResourceNameGeneratorpropNamesGenprivate booleanreadOnlyprivate java.util.Map<PdfObject,PdfName>resourceToNameprivate static java.lang.StringShprivate PdfResources.ResourceNameGeneratorshadingNamesGen
-
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 PdfNameaddColorSpace(PdfColorSpace cs)AddsPdfColorSpaceobject to the resources.PdfNameaddColorSpace(PdfObject colorSpace)AddsPdfObjectto the resources as color space.PdfNameaddExtGState(PdfExtGState extGState)AddsPdfExtGStateobject to the resources.PdfNameaddExtGState(PdfDictionary extGState)AddsPdfDictionaryto the resources as graphics state parameter dictionary.PdfNameaddFont(PdfDocument pdfDocument, PdfFont font)Adds font to resources and registers PdfFont in the document for further flushing.PdfNameaddForm(PdfStream form)AddsPdfStreamto the resources as form.PdfNameaddForm(PdfFormXObject form)AddsPdfFormXObjectobject to the resources.PdfNameaddForm(PdfFormXObject form, PdfName name)Adds the given Form XObject to the current instance ofPdfResources.PdfNameaddImage(PdfStream image)AddsPdfStreamto the resources as image.PdfNameaddImage(PdfImageXObject image)AddsPdfImageXObjectobject to the resources.PdfNameaddPattern(PdfPattern pattern)AddsPdfPatternobject to the resources.PdfNameaddPattern(PdfDictionary pattern)AddsPdfDictionaryto the resources as pattern.PdfNameaddProperties(PdfDictionary properties)AddsPdfDictionaryto the resources as properties list.protected voidaddResource(PdfObject resource, PdfName resType, PdfName resName)(package private) PdfNameaddResource(PdfObject resource, PdfResources.ResourceNameGenerator nameGen)(package private) <T extends PdfObject>
PdfNameaddResource(PdfObjectWrapper<T> resource, PdfResources.ResourceNameGenerator nameGen)PdfNameaddShading(AbstractPdfShading shading)AddsAbstractPdfShadingobject to the resources.PdfNameaddShading(PdfDictionary shading)AddsPdfDictionaryto the resources as shading dictionary.protected voidbuildResources(PdfDictionary dictionary)private voidcheckAndResolveCircularReferences(PdfObject pdfObject)PdfColorSpacegetColorSpace(PdfName name)PdfFormXObjectgetForm(PdfName name)PdfImageXObjectgetImage(PdfName name)PdfPatterngetPattern(PdfName name)PdfExtGStategetPdfExtGState(PdfName name)PdfArraygetProcSet()Gets the array of predefined procedure set names (see ISO-320001 Paragraph 14.2).PdfObjectgetProperties(PdfName name)PdfDictionarygetResource(PdfName resType)Get thePdfDictionaryobject that that contain resources of specified type.PdfNamegetResourceName(PdfObject resource)Gets the mapped resource name of the givenPdfObject.<T extends PdfObject>
PdfNamegetResourceName(PdfObjectWrapper<T> resource)Gets the mapped resource name of thePdfObjectunder 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.PdfObjectgetResourceObject(PdfName resType, PdfName resName)Get thePdfObjectobject with specified type and name.AbstractPdfShadinggetShading(PdfName name)protected booleanisModified()protected booleanisReadOnly()protected booleanisWrappedObjectMustBeIndirect()Defines if the object behind this wrapper must be an indirect object in the resultant document.voidsetDefaultCmyk(PdfColorSpace defaultCs)Sets the value of default CMYK Color Space (see ISO-320001 Paragraph 8.6.5.6).voidsetDefaultGray(PdfColorSpace defaultCs)Sets the value of default Gray Color Space (see ISO-320001 Paragraph 8.6.5.6).voidsetDefaultRgb(PdfColorSpace defaultCs)Sets the value of default RGB Color Space (see ISO-320001 Paragraph 8.6.5.6).PdfObjectWrapper<PdfDictionary>setModified()voidsetProcSet(PdfArray array)Sets the array of predefined procedure set names (see ISO-320001 Paragraph 14.2).protected voidsetReadOnly(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- thePdfDictionaryobject 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- aPdfDocumentinstance to which the font is added for further flushingfont- aPdfFontinstance to be added- Returns:
- added font resource name.
-
addImage
public PdfName addImage(PdfImageXObject image)
AddsPdfImageXObjectobject to the resources.- Parameters:
image- thePdfImageXObjectto add.- Returns:
- added image resource name.
-
addImage
public PdfName addImage(PdfStream image)
AddsPdfStreamto the resources as image.- Parameters:
image- thePdfStreamto add.- Returns:
- added image resources name.
-
getImage
public PdfImageXObject getImage(PdfName name)
-
addForm
public PdfName addForm(PdfFormXObject form)
AddsPdfFormXObjectobject to the resources.- Parameters:
form- thePdfFormXObjectto add.- Returns:
- added form resource name.
-
addForm
public PdfName addForm(PdfStream form)
AddsPdfStreamto the resources as form.- Parameters:
form- thePdfStreamto 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
PdfNameof the newly added resource
-
getForm
public PdfFormXObject getForm(PdfName name)
-
addExtGState
public PdfName addExtGState(PdfExtGState extGState)
AddsPdfExtGStateobject to the resources.- Parameters:
extGState- thePdfExtGStateto add.- Returns:
- added graphics state parameter dictionary resource name.
-
addExtGState
public PdfName addExtGState(PdfDictionary extGState)
AddsPdfDictionaryto the resources as graphics state parameter dictionary.- Parameters:
extGState- thePdfDictionaryto add.- Returns:
- added graphics state parameter dictionary resources name.
-
getPdfExtGState
public PdfExtGState getPdfExtGState(PdfName name)
-
addProperties
public PdfName addProperties(PdfDictionary properties)
AddsPdfDictionaryto the resources as properties list.- Parameters:
properties- thePdfDictionaryto add.- Returns:
- added properties list resources name.
-
addColorSpace
public PdfName addColorSpace(PdfColorSpace cs)
AddsPdfColorSpaceobject to the resources.- Parameters:
cs- thePdfColorSpaceto add.- Returns:
- added color space resource name.
-
addColorSpace
public PdfName addColorSpace(PdfObject colorSpace)
AddsPdfObjectto the resources as color space.- Parameters:
colorSpace- thePdfObjectto add.- Returns:
- added color space resources name.
-
getColorSpace
public PdfColorSpace getColorSpace(PdfName name)
-
addPattern
public PdfName addPattern(PdfPattern pattern)
AddsPdfPatternobject to the resources.- Parameters:
pattern- thePdfPatternto add.- Returns:
- added pattern resource name.
-
addPattern
public PdfName addPattern(PdfDictionary pattern)
AddsPdfDictionaryto the resources as pattern.- Parameters:
pattern- thePdfDictionaryto add.- Returns:
- added pattern resources name.
-
getPattern
public PdfPattern getPattern(PdfName name)
-
addShading
public PdfName addShading(AbstractPdfShading shading)
AddsAbstractPdfShadingobject to the resources.- Parameters:
shading- theAbstractPdfShadingto add.- Returns:
- added shading resource name.
-
addShading
public PdfName addShading(PdfDictionary shading)
AddsPdfDictionaryto the resources as shading dictionary.- Parameters:
shading- thePdfDictionaryto 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:
setModifiedin 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 thePdfObjectunder 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
nullif 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 thePdfDictionaryobject 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
PdfDictionaryobject containing all resources of specified type, ornullin case of incorrect resource type.
-
getResourceObject
public PdfObject getResourceObject(PdfName resType, PdfName resName)
Get thePdfObjectobject 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
PdfObjectwith specified name in the resources of specified type ornullin case of incorrect type or missing resource with such name.
-
isWrappedObjectMustBeIndirect
protected boolean isWrappedObjectMustBeIndirect()
Description copied from class:PdfObjectWrapperDefines 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:
isWrappedObjectMustBeIndirectin 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)
-
-