use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDPage method getThreadBeads.
/**
* This will get a list of PDThreadBead objects, which are article threads in the document. This
* will return an empty list if there are no thread beads.
*
* @return A list of article threads on this page, never null. The returned list is backed by
* the beads COSArray, so any adding or deleting in this list will change the document too.
*/
public List<PDThreadBead> getThreadBeads() {
COSArray beads = (COSArray) page.getDictionaryObject(COSName.B);
if (beads == null) {
beads = new COSArray();
}
List<PDThreadBead> pdObjects = new ArrayList<PDThreadBead>();
for (int i = 0; i < beads.size(); i++) {
COSBase base = beads.getObject(i);
PDThreadBead bead = null;
// in some cases the bead is null
if (base instanceof COSDictionary) {
bead = new PDThreadBead((COSDictionary) base);
}
pdObjects.add(bead);
}
return new COSArrayList<PDThreadBead>(pdObjects, beads);
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDDocumentCatalog method getOutputIntents.
/**
* Get the list of OutputIntents defined in the document.
*
* @return The list of PDOutputIntent
*/
public List<PDOutputIntent> getOutputIntents() {
List<PDOutputIntent> retval = new ArrayList<PDOutputIntent>();
COSArray array = (COSArray) root.getDictionaryObject(COSName.OUTPUT_INTENTS);
if (array != null) {
for (COSBase cosBase : array) {
if (cosBase instanceof COSObject) {
cosBase = ((COSObject) cosBase).getObject();
}
PDOutputIntent oi = new PDOutputIntent((COSDictionary) cosBase);
retval.add(oi);
}
}
return retval;
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDPageTree method getInheritableAttribute.
/**
* Returns the given attribute, inheriting from parent tree nodes if necessary.
*
* @param node page object
* @param key the key to look up
* @return COS value for the given key
*/
public static COSBase getInheritableAttribute(COSDictionary node, COSName key) {
COSBase value = node.getDictionaryObject(key);
if (value != null) {
return value;
}
COSBase base = node.getDictionaryObject(COSName.PARENT, COSName.P);
if (base instanceof COSDictionary) {
COSDictionary parent = (COSDictionary) base;
if (COSName.PAGES.equals(parent.getDictionaryObject(COSName.TYPE))) {
return getInheritableAttribute(parent, key);
}
}
return null;
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDResources method add.
/**
* Adds the given resource if it does not already exist.
*/
private COSName add(COSName kind, String prefix, COSObjectable object) {
// return the existing key if the item exists already
COSDictionary dict = (COSDictionary) resources.getDictionaryObject(kind);
if (dict != null && dict.containsValue(object.getCOSObject())) {
return dict.getKeyForValue(object.getCOSObject());
}
// AcroForm default resources of a loaded PDF.
if (dict != null && COSName.FONT.equals(kind)) {
for (Map.Entry<COSName, COSBase> entry : dict.entrySet()) {
if (entry.getValue() instanceof COSObject && object.getCOSObject() == ((COSObject) entry.getValue()).getObject()) {
return entry.getKey();
}
}
}
// add the item with a new key
COSName name = createKey(kind, prefix);
put(kind, name, object);
return name;
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDResources method isImageXObject.
/**
* Tells whether the XObject resource with the given name is an image.
*
* @param name Name of the XObject resource.
* @return true if it is an image XObject, false if not.
*/
public boolean isImageXObject(COSName name) {
// get the instance
COSBase value = get(COSName.XOBJECT, name);
if (value == null) {
return false;
} else if (value instanceof COSObject) {
value = ((COSObject) value).getObject();
}
if (!(value instanceof COSStream)) {
return false;
}
COSStream stream = (COSStream) value;
return COSName.IMAGE.equals(stream.getCOSName(COSName.SUBTYPE));
}
Aggregations