Java Code Examples for org.apache.pdfbox.cos.COSArray#remove()

The following examples show how to use org.apache.pdfbox.cos.COSArray#remove() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PDStructureElement.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 2
Source File: PDStructureElement.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 3
Source File: PDUserAttributeObject.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Removes a user property.
 * 
 * @param userProperty the user property
 */
public void removeUserProperty(PDUserProperty userProperty)
{
    if (userProperty == null)
    {
        return;
    }
    COSArray p = (COSArray) this.getCOSObject().getDictionaryObject(COSName.P);
    p.remove(userProperty.getCOSObject());
    this.notifyChanged();
}
 
Example 4
Source File: PDSeedValueCertificate.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * removes a subject from the list
 *
 * @param subject byte array containing DER-encoded X.509v3 certificate
 */
public void removeSubject(byte[] subject)
{
    COSBase base = this.dictionary.getDictionaryObject(COSName.SUBJECT);
    if (base instanceof COSArray)
    {
        COSArray array = (COSArray) base;
        array.remove(new COSString(subject));
    }
}
 
Example 5
Source File: PDSeedValueCertificate.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Removes a key usage extension
 *
 * @param keyUsageExtension ASCII string that consists of {0, 1, X}
 */
public void removeKeyUsage(String keyUsageExtension)
{
    COSBase base = this.dictionary.getDictionaryObject(COSName.KEY_USAGE);
    if (base instanceof COSArray)
    {
        COSArray array = (COSArray) base;
        array.remove(new COSString(keyUsageExtension));
    }
}
 
Example 6
Source File: PDSeedValueCertificate.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Removes an issuer from the issuers list
 *
 * @param issuer A byte array containing DER-encoded X.509v3 certificate
 */
public void removeIssuer(byte[] issuer)
{
    COSBase base = this.dictionary.getDictionaryObject(COSName.ISSUER);
    if (base instanceof COSArray)
    {
        COSArray array = (COSArray) base;
        array.remove(new COSString(issuer));
    }
}
 
Example 7
Source File: PDSeedValueCertificate.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * removes an OID from the list
 *
 * @param oid the object identifier to be removed.
 */
public void removeOID(byte[] oid)
{
    COSBase base = this.dictionary.getDictionaryObject(COSName.OID);
    if (base instanceof COSArray)
    {
        COSArray array = (COSArray) base;
        array.remove(new COSString(oid));
    }
}
 
Example 8
Source File: COSParser.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
private int checkPagesDictionary(COSDictionary pagesDict, Set<COSObject> set)
{
    // check for kids
    COSBase kids = pagesDict.getDictionaryObject(COSName.KIDS);
    int numberOfPages = 0;
    if (kids instanceof COSArray)
    {
        COSArray kidsArray = (COSArray) kids;
        List<? extends COSBase> kidsList = kidsArray.toList();
        for (COSBase kid : kidsList)
        {
            if (!(kid instanceof COSObject) || set.contains((COSObject) kid))
            {
                kidsArray.remove(kid);
                continue;
            }
            COSObject kidObject = (COSObject) kid;
            COSBase kidBaseobject = kidObject.getObject();
            // object wasn't dereferenced -> remove it
            if (kidBaseobject == null || kidBaseobject.equals(COSNull.NULL))
            {
                LOG.warn("Removed null object " + kid + " from pages dictionary");
                kidsArray.remove(kid);
            }
            else if (kidBaseobject instanceof COSDictionary)
            {
                COSDictionary kidDictionary = (COSDictionary) kidBaseobject;
                COSName type = kidDictionary.getCOSName(COSName.TYPE);
                if (COSName.PAGES.equals(type))
                {
                    // process nested pages dictionaries
                    set.add(kidObject);
                    numberOfPages += checkPagesDictionary(kidDictionary, set);
                }
                else if (COSName.PAGE.equals(type))
                {
                    // count pages
                    numberOfPages++;
                }
            }
        }
    }
    // fix counter
    pagesDict.setInt(COSName.COUNT, numberOfPages);
    return numberOfPages;
}
 
Example 9
Source File: BaseParser.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * This will parse a PDF array object.
 *
 * @return The parsed PDF array.
 *
 * @throws IOException If there is an error parsing the stream.
 */
protected COSArray parseCOSArray() throws IOException
{
    long startPosition = seqSource.getPosition();
    readExpectedChar('[');
    COSArray po = new COSArray();
    COSBase pbo;
    skipSpaces();
    int i;
    while( ((i = seqSource.peek()) > 0) && ((char)i != ']') )
    {
        pbo = parseDirObject();
        if( pbo instanceof COSObject )
        {
            // We have to check if the expected values are there or not PDFBOX-385
            if (po.size() > 0 && po.get(po.size() - 1) instanceof COSInteger)
            {
                COSInteger genNumber = (COSInteger)po.remove( po.size() -1 );
                if (po.size() > 0 && po.get(po.size() - 1) instanceof COSInteger)
                {
                    COSInteger number = (COSInteger)po.remove( po.size() -1 );
                    COSObjectKey key = new COSObjectKey(number.longValue(), genNumber.intValue());
                    pbo = getObjectFromPool(key);
                }
                else
                {
                    // the object reference is somehow wrong
                    pbo = null;
                }
            }
            else
            {
                pbo = null;
            }
        }
        if( pbo != null )
        {
            po.add( pbo );
        }
        else
        {
            //it could be a bad object in the array which is just skipped
            LOG.warn("Corrupt object reference at offset " +
                    seqSource.getPosition() + ", start offset: " + startPosition);

            // This could also be an "endobj" or "endstream" which means we can assume that
            // the array has ended.
            String isThisTheEnd = readString();
            seqSource.unread(isThisTheEnd.getBytes(ISO_8859_1));
            if(ENDOBJ_STRING.equals(isThisTheEnd) || ENDSTREAM_STRING.equals(isThisTheEnd))
            {
                return po;
            }
        }
        skipSpaces();
    }
    // read ']'
    seqSource.read(); 
    skipSpaces();
    return po;
}