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

The following examples show how to use org.apache.pdfbox.cos.COSArray#set() . 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: PDLab.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private void setComponentRangeArray(PDRange range, int index)
{
    COSArray rangeArray = (COSArray) dictionary.getDictionaryObject(COSName.RANGE);
    if (rangeArray == null)
    {
        rangeArray = getDefaultRangeArray();
    }
    if (range == null)
    {
        // reset to defaults
        rangeArray.set(index, new COSFloat(-100));
        rangeArray.set(index + 1, new COSFloat(100));
    }
    else
    {
        rangeArray.set(index, new COSFloat(range.getMin()));
        rangeArray.set(index + 1, new COSFloat(range.getMax()));
    }
    dictionary.setItem(COSName.RANGE, rangeArray);
    initialColor = null;
}
 
Example 2
Source File: PDInlineImage.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private PDColorSpace createColorSpace(COSBase cs) throws IOException
{
    if (cs instanceof COSName)
    {
        return PDColorSpace.create(toLongName(cs), resources);
    }

    if (cs instanceof COSArray && ((COSArray) cs).size() > 1)
    {
        COSArray srcArray = (COSArray) cs;
        COSBase csType = srcArray.get(0);
        if (COSName.I.equals(csType) || COSName.INDEXED.equals(csType))
        {
            COSArray dstArray = new COSArray();
            dstArray.addAll(srcArray);
            dstArray.set(0, COSName.INDEXED);
            dstArray.set(1, toLongName(srcArray.get(1)));
            return PDColorSpace.create(dstArray, resources);
        }

        throw new IOException("Illegal type of inline image color space: " + csType);
    }

    throw new IOException("Illegal type of object for inline image color space: " + cs);
}
 
Example 3
Source File: RebuildParentTreeFromStructure.java    From testarea-pdfbox2 with Apache License 2.0 6 votes vote down vote up
/**
 * This method creates a new parent tree in the given structure
 * tree root based on the contents of the mapping of page and
 * MCID to structure node.
 * 
 * @see #rebuildParentTree(PDDocument)
 */
void rebuildParentTreeFromData(PDStructureTreeRoot root, Map<PDPage, Map<Integer, PDStructureNode>> parentsByPage) {
    int parentTreeMaxkey = -1;
    Map<Integer, COSArray> numbers = new HashMap<>();

    for (Map.Entry<PDPage, Map<Integer, PDStructureNode>> entry : parentsByPage.entrySet()) {
        int parentsId = entry.getKey().getCOSObject().getInt(COSName.STRUCT_PARENTS);
        if (parentsId < 0) {
            System.err.printf("Page without StructsParents. Ignoring %s MCIDs.\n", entry.getValue().size());
        } else {
            if (parentTreeMaxkey < parentsId)
                parentTreeMaxkey = parentsId;
            COSArray array = new COSArray();
            for (Map.Entry<Integer, PDStructureNode> subEntry : entry.getValue().entrySet()) {
                array.growToSize(subEntry.getKey() + 1);
                array.set(subEntry.getKey(), subEntry.getValue());
            }
            numbers.put(parentsId, array);
        }
    }

    PDNumberTreeNode numberTreeNode = new PDNumberTreeNode(PDParentTreeValue.class);
    numberTreeNode.setNumbers(numbers);
    root.setParentTree(numberTreeNode);
    root.setParentTreeNextKey(parentTreeMaxkey + 1);
}