Search in sources :

Example 21 with COSName

use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.

the class PDStructureElement method removeAttribute.

/**
 * Removes an attribute object.
 *
 * @param attributeObject the attribute object
 */
public void removeAttribute(PDAttributeObject attributeObject) {
    COSName key = COSName.A;
    COSBase a = this.getCOSObject().getDictionaryObject(key);
    if (a instanceof COSArray) {
        COSArray array = (COSArray) a;
        array.remove(attributeObject.getCOSObject());
        if ((array.size() == 2) && (array.getInt(1) == 0)) {
            this.getCOSObject().setItem(key, array.getObject(0));
        }
    } else {
        COSBase directA = a;
        if (a instanceof COSObject) {
            directA = ((COSObject) a).getObject();
        }
        if (attributeObject.getCOSObject().equals(directA)) {
            this.getCOSObject().setItem(key, null);
        }
    }
    attributeObject.setStructureElement(null);
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSObject(com.tom_roush.pdfbox.cos.COSObject) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 22 with COSName

use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.

the class PDStructureElement method setAttributes.

/**
 * Sets the attributes together with their revision numbers (A).
 *
 * @param attributes the attributes
 */
public void setAttributes(Revisions<PDAttributeObject> attributes) {
    COSName key = COSName.A;
    if ((attributes.size() == 1) && (attributes.getRevisionNumber(0) == 0)) {
        PDAttributeObject attributeObject = attributes.getObject(0);
        attributeObject.setStructureElement(this);
        this.getCOSObject().setItem(key, attributeObject);
        return;
    }
    COSArray array = new COSArray();
    for (int i = 0; i < attributes.size(); i++) {
        PDAttributeObject attributeObject = attributes.getObject(i);
        attributeObject.setStructureElement(this);
        int revisionNumber = attributes.getRevisionNumber(i);
        if (revisionNumber < 0) {
            throw new IllegalArgumentException("The revision number shall be > -1");
        }
        array.add(attributeObject);
        array.add(COSInteger.get(revisionNumber));
    }
    this.getCOSObject().setItem(key, array);
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) COSArray(com.tom_roush.pdfbox.cos.COSArray)

Example 23 with COSName

use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.

the class PDStructureElement method removeClassName.

/**
 * Removes a class name.
 *
 * @param className the class name
 */
public void removeClassName(String className) {
    if (className == null) {
        return;
    }
    COSName key = COSName.C;
    COSBase c = this.getCOSObject().getDictionaryObject(key);
    COSName name = COSName.getPDFName(className);
    if (c instanceof COSArray) {
        COSArray array = (COSArray) c;
        array.remove(name);
        if ((array.size() == 2) && (array.getInt(1) == 0)) {
            this.getCOSObject().setItem(key, array.getObject(0));
        }
    } else {
        COSBase directC = c;
        if (c instanceof COSObject) {
            directC = ((COSObject) c).getObject();
        }
        if (name.equals(directC)) {
            this.getCOSObject().setItem(key, null);
        }
    }
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSObject(com.tom_roush.pdfbox.cos.COSObject) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 24 with COSName

use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.

the class PDStructureElement method setClassNames.

/**
 * Sets the class names together with their revision numbers (C).
 *
 * @param classNames the class names
 */
public void setClassNames(Revisions<String> classNames) {
    if (classNames == null) {
        return;
    }
    COSName key = COSName.C;
    if ((classNames.size() == 1) && (classNames.getRevisionNumber(0) == 0)) {
        String className = classNames.getObject(0);
        this.getCOSObject().setName(key, className);
        return;
    }
    COSArray array = new COSArray();
    for (int i = 0; i < classNames.size(); i++) {
        String className = classNames.getObject(i);
        int revisionNumber = classNames.getRevisionNumber(i);
        if (revisionNumber < 0) {
            throw new IllegalArgumentException("The revision number shall be > -1");
        }
        array.add(COSName.getPDFName(className));
        array.add(COSInteger.get(revisionNumber));
    }
    this.getCOSObject().setItem(key, array);
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) COSArray(com.tom_roush.pdfbox.cos.COSArray)

Example 25 with COSName

use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.

the class PDStructureElement method addClassName.

/**
 * Adds a class name.
 *
 * @param className the class name
 */
public void addClassName(String className) {
    if (className == null) {
        return;
    }
    COSName key = COSName.C;
    COSBase c = this.getCOSObject().getDictionaryObject(key);
    COSArray array;
    if (c instanceof COSArray) {
        array = (COSArray) c;
    } else {
        array = new COSArray();
        if (c != null) {
            array.add(c);
            array.add(COSInteger.get(0));
        }
    }
    this.getCOSObject().setItem(key, array);
    array.add(COSName.getPDFName(className));
    array.add(COSInteger.get(this.getRevisionNumber()));
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Aggregations

COSName (com.tom_roush.pdfbox.cos.COSName)83 COSBase (com.tom_roush.pdfbox.cos.COSBase)50 COSArray (com.tom_roush.pdfbox.cos.COSArray)27 IOException (java.io.IOException)24 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)23 COSObject (com.tom_roush.pdfbox.cos.COSObject)11 COSString (com.tom_roush.pdfbox.cos.COSString)11 HashMap (java.util.HashMap)10 Map (java.util.Map)10 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)9 COSStream (com.tom_roush.pdfbox.cos.COSStream)7 PDFormXObject (com.tom_roush.pdfbox.pdmodel.graphics.form.PDFormXObject)7 MissingOperandException (com.tom_roush.pdfbox.contentstream.operator.MissingOperandException)5 COSInteger (com.tom_roush.pdfbox.cos.COSInteger)5 COSNumber (com.tom_roush.pdfbox.cos.COSNumber)5 PDXObject (com.tom_roush.pdfbox.pdmodel.graphics.PDXObject)5 PDRectangle (com.tom_roush.pdfbox.pdmodel.common.PDRectangle)4 PDTransparencyGroup (com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup)4 OutputStream (java.io.OutputStream)4 Operator (com.tom_roush.pdfbox.contentstream.operator.Operator)3