This represents a set of resources available at the page/pages/stream level.
Method from org.apache.pdfbox.pdmodel.PDResources Detail: |
public COSDictionary getCOSDictionary() {
return resources;
}
This will get the underlying dictionary. |
public COSBase getCOSObject() {
return resources;
}
Convert this standard java object to a COS object. |
public Map getColorSpaces() throws IOException {
Map retval = null;
COSDictionary colorspaces = (COSDictionary)resources.getDictionaryObject( COSName.getPDFName( "ColorSpace" ) );
if( colorspaces != null )
{
Map actuals = new HashMap();
retval = new COSDictionaryMap( actuals, colorspaces );
for( COSName csName : colorspaces.keySet() )
{
COSBase cs = colorspaces.getDictionaryObject( csName );
actuals.put( csName.getName(), PDColorSpaceFactory.createColorSpace( cs ) );
}
}
return retval;
}
This will get the map of colorspaces. This will return null if the underlying
resources dictionary does not have a colorspace dictionary. The keys are string
and the values are PDColorSpace objects. |
public Map getFonts() throws IOException {
return getFonts( null );
}
This will get the map of fonts. This will never return null. The keys are string
and the values are PDFont objects. |
public Map getFonts(Map fontCache) throws IOException {
Map retval = null;
COSDictionary fonts = (COSDictionary)resources.getDictionaryObject( COSName.FONT );
if( fonts == null )
{
fonts = new COSDictionary();
resources.setItem( COSName.FONT, fonts );
}
Map actuals = new HashMap();
retval = new COSDictionaryMap( actuals, fonts );
for( COSName fontName : fonts.keySet() )
{
COSBase font = fonts.getDictionaryObject( fontName );
//data-000174.pdf contains a font that is a COSArray, looks to be an error in the
//PDF, we will just ignore entries that are not dictionaries.
if( font instanceof COSDictionary )
{
COSDictionary fontDictionary = (COSDictionary)font;
actuals.put( fontName.getName(), PDFontFactory.createFont( fontDictionary, fontCache ));
}
}
return retval;
}
This will get the map of fonts. This will never return null. The keys are string
and the values are PDFont objects. |
public Map getGraphicsStates() {
Map retval = null;
COSDictionary states = (COSDictionary)resources.getDictionaryObject( COSName.EXT_G_STATE );
if( states != null )
{
Map actuals = new HashMap();
retval = new COSDictionaryMap( actuals, states );
for( COSName name : states.keySet() )
{
COSDictionary dictionary = (COSDictionary)states.getDictionaryObject( name );
actuals.put( name.getName(), new PDExtendedGraphicsState( dictionary ) );
}
}
return retval;
}
This will get the map of graphic states. This will return null if the underlying
resources dictionary does not have a graphics dictionary. The keys are the graphic state
name as a String and the values are PDExtendedGraphicsState objects. |
public Map getImages() throws IOException {
Map retval = null;
COSDictionary images = (COSDictionary)resources.getDictionaryObject( COSName.XOBJECT );
if( images == null )
{
images = new COSDictionary();
resources.setItem( COSName.XOBJECT, images );
}
Map actuals = new HashMap();
retval = new COSDictionaryMap( actuals, images );
for( COSName imageName : images.keySet() )
{
COSStream image = (COSStream)(images.getDictionaryObject(imageName));
COSName subType =(COSName)image.getDictionaryObject(COSName.SUBTYPE);
if( subType.equals(COSName.IMAGE) )
{
PDXObjectImage ximage = (PDXObjectImage)PDXObject.createXObject( image );
if( ximage !=null )
{
actuals.put( imageName.getName(), ximage);
}
}
}
return retval;
}
This will get the map of images. An empty map will be returned if there
are no underlying images.
So far the keys are COSName of the image
and the value is the corresponding PDXObjectImage. |
public Map getXObjects() throws IOException {
Map retval = null;
COSDictionary xobjects = (COSDictionary)resources.getDictionaryObject( COSName.XOBJECT );
if( xobjects == null )
{
xobjects = new COSDictionary();
resources.setItem( COSName.XOBJECT, xobjects );
}
Map actuals = new HashMap();
retval = new COSDictionaryMap( actuals, xobjects );
for( COSName objName : xobjects.keySet() )
{
COSBase cosObject = xobjects.getDictionaryObject(objName);
PDXObject xobject = PDXObject.createXObject( cosObject );
if( xobject !=null )
{
actuals.put( objName.getName(), xobject);
}
}
return retval;
}
This will get the map of PDXObjects that are in the resource dictionary. |
public void setColorSpaces(Map colorspaces) {
resources.setItem( COSName.COLORSPACE, COSDictionaryMap.convert( colorspaces ) );
}
This will set the map of colorspaces. |
public void setFonts(Map fonts) {
resources.setItem( COSName.FONT, COSDictionaryMap.convert( fonts ) );
}
This will set the map of fonts. |
public void setGraphicsStates(Map states) {
Iterator iter = states.keySet().iterator();
COSDictionary dic = new COSDictionary();
while( iter.hasNext() )
{
String name = (String)iter.next();
PDExtendedGraphicsState state = (PDExtendedGraphicsState)states.get( name );
dic.setItem( COSName.getPDFName( name ), state.getCOSObject() );
}
resources.setItem( COSName.EXT_G_STATE, dic );
}
This will set the map of graphics states. |